Jump to content

[SOLVED] I Really need to learn about " and ' ...


chrisfane

Recommended Posts

i seem to be constantly falling over hurdles with my use's of " and ' .  Im currently trying to write a mysql query which uses the result of a previous query, for one of its parameters.  i have previously always used ...

 

". $row2['SeatVers'] ."

 

to insert the result of a mysql query, but obviously this doesnt worked when encased in the double quotes used for the sql text string, and if im not mistaken if u use a single quote it refers to it as a static value rather than dynamic. 

 

	$result2 = mysql_query("select count(success) , SeatVers , ISAVers from SeatPub where success='1' and SeatVers=". $row['SeatVers'] ." group by ISAVers")
or die(mysql_error());

 

 

when using the code above i get the following error message, which i assume is because i am terminating the quotes before the end of the sql query, how should i go about modifying the above code to work correctly ?

 

 

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '9.005 group by ISAVers' at line 1"

 

Thanks for helping out a newbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/67306-solved-i-really-need-to-learn-about-and/
Share on other sites

Your use is right by PHP - it's MySQL that has a problem.

SeatVers=". $row['SeatVers'] ." group

Needs to be:

SeatVers='". $row['SeatVers'] ."' group

Note the single quotes surrounding the variable. That makes it a string in SQL. Even though you close the PHP string, you're starting a MySQL string and then closing it around the variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.