Page 1 of 1

php code error

Posted: Tue Mar 07, 2006 9:57 pm
by PHPNERD
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


can someone please tell me the error in the following code?

Parse error: parse error, unexpected T_STRING, expecting ',' or ';'

Code: Select all

echo "<td><a href="http://www.xxx.com/cart.php?action=add&item=".$row[product_id].""target="_blank" onMouseOver="window.status='Add To Cart!'; return true;" onMouseOut="window.status=''; return true;" onClick="window.open(this.href,0,'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=700,height=400,top=5,left=5, resizable=yes');return false">Add To Cart!</a></td>\n";

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Mar 07, 2006 10:00 pm
by feyd
take a look with syntax highlighting on. :)

Posted: Tue Mar 07, 2006 10:09 pm
by PHPNERD
not to be rude but i just don't see it. I need another set of eyes please

Posted: Tue Mar 07, 2006 10:22 pm
by nickman013
You have quotation conflicts.

I suggest you read about strings.

Posted: Tue Mar 07, 2006 10:44 pm
by RobertGonzalez
This is how PHP reads it...

Code: Select all

<?php
// Echo everything within the unescaped double quotes
echo "<td><a href=" //Oh wait, there is no semicolon, I should throw an error
?>
This is what it should look like...

Code: Select all

<?php
echo "<td><a href=\"http://www.xxx.com/cart.php?action=add&item=".$row[product_id]."\" target=\"_blank\" 
    onMouseOver=\"window.status='Add To Cart!'; return true;\" 
    onMouseOut=\"window.status=''; return true;\" 
    onClick=\"window.open(this.href,0,'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=700,height=400,top=5,left=5, resizable=yes');return false\">Add To Cart!</a></td>\n"; 
?>

Posted: Tue Mar 07, 2006 11:43 pm
by PHPNERD
Thank you I was forgetting all about my \'s :lol:

Posted: Tue Mar 07, 2006 11:50 pm
by Citizen
PHPNERD wrote:Thank you I was forgetting all about my \'s :lol:
You could use echo '<a href="link..... instead of \ing all of your standard quotation marks. Basically, using ' instead of " for setting off the php line.

Posted: Wed Mar 08, 2006 2:02 am
by s.dot
Citizen wrote:
PHPNERD wrote:Thank you I was forgetting all about my \'s :lol:
You could use echo '<a href="link..... instead of \ing all of your standard quotation marks. Basically, using ' instead of " for setting off the php line.
He wouldn't be able to because he's evaluating $variables inside the string. unless he concatenated them like 'this is a '.$variable.' right here'; which would be more confusing than just escaping the " with \.

Just remember a string with double quotes is everything between " and "
So if you have a " in there but you don't want it to end the string, escape it with a \, and you're all good ;)

Posted: Wed Mar 08, 2006 2:38 am
by RobertGonzalez
Citizen wrote:
PHPNERD wrote:Thank you I was forgetting all about my \'s :lol:
You could use echo '<a href="link..... instead of \ing all of your standard quotation marks. Basically, using ' instead of " for setting off the php line.
For the link he was echo'ing, this would need escaping also because of the calls to JavaScript functions. Regardless of the type of quote he used, they would need to be escaped.