Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.