Updating a table

I have the following code in my program:

$query = “UPDATE current SET currLocation = $currentLocation, comment = $content WHERE userID = $id LIMIT 1”;
mysql_query($query) or die(‘Error, query failed’);

The above fails every time. This code works:

$query = “UPDATE current SET currLocation = $currentLocation WHERE userID = $id LIMIT 1”;
mysql_query($query) or die(‘Error, query failed’);

I suspect I have an issue with types. currLocation is type text; $currentLocation is type string. Any ideas on how I can resolve this??
Or maybe I am going blind and have a syntax error.

thanks in Advance!

First… Interesting Username… Are you a member?

Next:
Try “Quoting” your data.

In a SQL Query Strings need to be quoted. (I presume so do Text). Numbers (integers, decimals) are not required to be quoted but CAN be.

Alter you query FROM (original)
$query = “UPDATE current SET currLocation = $currentLocation, comment = $content WHERE userID = $id LIMIT 1”;

TO: (inline quoting)
$query = “UPDATE current SET currLocation = ‘$currentLocation’, comment = ‘$content’ WHERE userID = $id LIMIT 1”;

Even better might be: (Quoting and separating the variables out)
$query = ‘UPDATE current SET currLocation = "’.$currentLocation.’", comment = “’.$content.’” WHERE userID = $id LIMIT 1";

Also presumably the userID is a type INT.

Hope this helps

I’m not just a member… I (used to be) President.

The quotes worked!

I did a gettype on the variable ($content) and it was string. So it make sense that I would need quotes.
I didn’t need them for $userID $currentLocation (which are type int).

Thanks!!

Glad I could help.

I have been a member for 10 years now. Not president, but I was President of our Student IEEE club in college.

Sponsor our Newsletter | Privacy Policy | Terms of Service