Page 1 of 1

weird (to me) error in simple mysql query

Posted: Thu Dec 22, 2005 12:25 pm
by hanzo

Code: Select all

<?
mysql_connect ('XXremovedXX','XXremovedXX','XXremovedXX')or die('Could not connect: ' . mysql_error());
mysql_select_db ('XXremovedXX');
$query0 = "UPDATE users SET order='2' WHERE email = 'emailertje@gmail.com'";
mysql_query ($query0) or die(mysql_error());
?>

gives me:
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 'order='2' WHERE email = 'emailertje@gmail.com'' at line 1
And I really haven't got any idea what I'm doing wrong :cry:


Thanks

Posted: Thu Dec 22, 2005 12:28 pm
by Burrito
for all intents and purposes, that should work.

what are the field types on the db?

edit: as an aside, you should always escape your string vars with mysql_real_escape_string()

Posted: Thu Dec 22, 2005 12:33 pm
by John Cartwright
order is a reserved word.. use backticks ;)

Code: Select all

$query0 = "UPDATE `users` SET `order`='2' WHERE `email` = 'emailertje@gmail.com'";

Posted: Thu Dec 22, 2005 1:27 pm
by hanzo
Jcart wrote:order is a reserved word.. use backticks ;)

Code: Select all

$query0 = "UPDATE `users` SET `order`='2' WHERE `email` = 'emailertje@gmail.com'";
never could figer out that myself. thanks :!:

Posted: Thu Dec 22, 2005 1:38 pm
by Burrito
Jcart wrote:order is a reserved word.. use backticks ;)

Code: Select all

$query0 = "UPDATE `users` SET `order`='2' WHERE `email` = 'emailertje@gmail.com'";
yeah or that 8O