php code error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PHPNERD
Forum Newbie
Posts: 4
Joined: Tue Mar 07, 2006 12:35 pm

php code error

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

take a look with syntax highlighting on. :)
PHPNERD
Forum Newbie
Posts: 4
Joined: Tue Mar 07, 2006 12:35 pm

Post by PHPNERD »

not to be rude but i just don't see it. I need another set of eyes please
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

You have quotation conflicts.

I suggest you read about strings.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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"; 
?>
PHPNERD
Forum Newbie
Posts: 4
Joined: Tue Mar 07, 2006 12:35 pm

Post by PHPNERD »

Thank you I was forgetting all about my \'s :lol:
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply