ruslyrossi ruslyrossi - 3 months ago 18
PHP Question

error when try to update table name "order"

i try to update simple data to table name "order" but i still get error.

i try to many version query but still same ;

first try :
$result = mysql_query("UPDATE order SET order_status_id=200 WHERE order_id=75") or die(mysql_error());

second try :
$result = mysql_query("UPDATE order SET order_status_id='200' WHERE order_id='75'") or die(mysql_error());


error ;

first try :
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 SET order_id=200 WHERE order_id=75' at line 1

second try :
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 SET order_status_id='200' WHERE order_id='75'' at line 1

Table structure

order_id int(11)
order_status_id int(11)


i try to update others table just to make sure my query correct and all table can update.

*Im using Opencart and my site use https.

Thanks.

Answer

order is a reserved word in MySQL. You need to escape it with backticks:

UPDATE `order` SET order_status_id=200 WHERE order_id=75

See MySQL reserved words