Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 11-08-2010, 05:24 AM Some Syntax Help!
Novice Talker

Posts: 14
Location: UK
Trades: 0
Hi All, this is probably really simple - I've posted it into the PHP forum in a thread I had going there, but it's probably more suited to being in here...

At the moment I'm using a javascript/jquery combo to load pages into a container div on my site - The script looks something like this:

HTML Code:
HTML Code:
<script type="text/javascript">
function loadContent(elementSelector, sourceURL) {
$(""+elementSelector+"").load("http://www.website.com/test/"+sourceURL+"");
}
</script>
And a link looks like this:

HTML Code:
HTML Code:
<a href="javascript:loadContent('.content', 'test3.php');">Video</a>
Now, because of the Apostrophe's in this and the Apostrophes needed in my PHP code for the database field names I'm getting syntax errors, for example:

PHP Code:
PHP Code:
<a href="javascript:loadContent('.content', 'video.php?video={$info['title']}'');">{$info['title']}</a
Does anyone know a way I can make this work?!

EDIT: I've just re-read my post and realised it's a bit vague.

What I now have is a dynamically generated page, that depending on the link that is clicked, passes the variables using $_GET to a new page.

I'm trying to open this page in my content DIV, but due to the apostrophe marks in the PHP array item names it's throwing up syntax errors/not working with the code...

Hopefully that makes it all a bit clearer in conjunction with the above!

Last edited by hj8ag; 11-08-2010 at 09:42 AM.. Reason: To clarify issue
hj8ag is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-08-2010, 12:00 PM Re: Some Syntax Help!
Extreme Talker

Posts: 246
Trades: 0
I don't know PHP, but I'm almost positive you can escape the characters. Something like <a href="javascript:loadContent(\'.content\', \'video.php?video={$info[\'title\']}\'\');\">{$info[\'title\']}</a>

or something like that. This way when PHP renders it out it will see the apostrophe as an apostrophe.

At least I hope this is what it is.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 11-09-2010, 11:59 AM Re: Some Syntax Help!
Novice Talker

Posts: 14
Location: UK
Trades: 0
Just given that a go and it's throwing up errors still!
hj8ag is offline
Reply With Quote
View Public Profile
 
Old 11-09-2010, 12:12 PM Re: Some Syntax Help!
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
What are the errors.. And what log file are the errors appearing..
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 11-09-2010, 02:30 PM Re: PHP and Javascript Code error (possibly syntax related?!)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Where is the rest of that line of PHP code? Should it be something like this:
PHP Code:
<a href="javascript:loadContent('.content', 'video.php?video=<?php echo $info['title']; ?>'); ?>"><?php echo $info['title']; ?></a>
or is the entire thing a string:
PHP Code:
"<a href=\"javascript:loadContent('.content', 'video.php?video={$info['title']}');\">{$info['title']}</a>" 
You can escape quotes using \
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-09-2010 at 02:34 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-09-2010, 04:20 PM Re: Some Syntax Help!
Novice Talker

Posts: 14
Location: UK
Trades: 0
NullPointer, that last string worked perfectly, thanks. I think I must have had an extra quotation mark in there somewhere...

The full PHP is:

PHP Code:
<?php
$data 
mysql_query("SELECT * FROM video WHERE type = 'Promo' ORDER BY added DESC") or die(mysql_error());
$i 0
echo 
"<table class='griddy'>"
while(
$info mysql_fetch_array$data )) { 
    if(
$i === 0) echo "\n<tr>"
    echo 
"<td>"
    echo 
"<img class='still' src='../video/images/{$info['still']}' width='249px' height='148px' />";
    echo 
"<div class='title'><a href=\"javascript:loadContent('.content', 'video.php?video={$info['title']}');\">{$info['title']}</a></div>";
    echo 
"<div class='subtitle'>{$info['subtitle']}</div>";
    echo 
"</td>";
    if(
$i === 2) echo "</tr>"
    
$i++; 
}
if(
$i 0) echo "</tr>"
echo 
"</table>"
?>
Now I'm actually thinking of loading some of this into a separate page for SEO.

Are there any security measures I should think about when passing a variable in the URL?!

Last edited by hj8ag; 11-09-2010 at 04:30 PM..
hj8ag is offline
Reply With Quote
View Public Profile
 
Old 11-09-2010, 04:26 PM Re: Some Syntax Help!
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by hj8ag View Post
NullPointer, that last string worked perfectly, thanks. I think I must have had an extra quotation mark in there somewhere...

The full PHP is:

PHP Code:
<?php
$data 
mysql_query("SELECT * FROM video WHERE type = 'Promo' ORDER BY added DESC") or die(mysql_error());
$i 0//assign $i a starting value of 0
echo "<table class='griddy'>"
while(
$info mysql_fetch_array$data )) { 
    if(
$i === 0) echo "\n<tr>"
    echo 
"<td>"
    echo 
"<img class='still' src='../video/images/{$info['still']}' width='249px' height='148px' />";
    echo 
"<div class='title'><a href=\"javascript:loadContent('.content', 'video.php?video={$info['title']}');\">{$info['title']}</a></div>";
    echo 
"<div class='subtitle'>{$info['subtitle']}</div>";
    echo 
"</td>";
    if(
$i === 2) echo "</tr>"
    
$i++; //increase $i by 1 ($i = $i + 1)
}
if(
$i 0) echo "</tr>"
echo 
"</table>"
?>
Now I'm actually thinking of loading some of this into a separate page for SEO.

Are there any security measures I should think about when passing a variable in the URL?!
Yes,

If you put ANY of the data taken from the URL or from any kind of userinput you MUST clean the data before using it in things like databases.

You can use the mysql_real_escape_string and htmlentitys functions to help escape naughty hacking attemps.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 11-09-2010, 04:27 PM Re: Some Syntax Help!
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by hj8ag View Post
Are there any security measures I should think about when passing a variable in the URL?!
Just make sure you validate and sanitize it in video.php before doing anything with it (ie insert it into a query).

One way you can make your life easier when outputting a lot of text is to not bother trying to construct it all as strings:
PHP Code:
<?php 
$data 
mysql_query("SELECT * FROM video WHERE type = 'Promo' ORDER BY added DESC") or die(mysql_error()); 
$i 0//assign $i a starting value of 0 
echo "<table class='griddy'>";  
while(
$info mysql_fetch_array$data )) {  
    if(
$i === 0) echo "\n<tr>";
?>    
<td>  
<img class='still' src='../video/images/<?php echo $info['still']; ?>' width='249px' height='148px' />
<div class='title'><a href=\"javascript:loadContent('.content', 'video.php?video=<?php echo $info['title']; ?>');\"><?php echo $info['title']; ?></a></div>
<div class='subtitle'><?php echo $info['subtitle']; ?></div>
</td>
<?php
    
if($i === 2) echo "</tr>";  
    
$i++; //increase $i by 1 ($i = $i + 1) 

if(
$i 0) echo "</tr>";  
echo 
"</table>";  
?>
If for whatever reason you want to capture it as a string rather than output it immediately you can use an output buffer http://us2.php.net/manual/en/function.ob-start.php
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-09-2010 at 04:28 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-13-2010, 01:39 AM Re: Some Syntax Help!
Skilled Talker

Posts: 50
Name: Preet Punjabi
Trades: 0
Tnx to all friend to sharing these codes . it might help me to create some new task nd project
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
forumdiversity is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Some Syntax Help!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62062 seconds with 12 queries