Mysql error in php code
can't understand mysql error:
UPDATE static_pages SET order = " Some new data 222222
"Database error: 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 = "
$query = 'UPDATE someTable SET '.$key.' = "'.$value.'"';
Here is $key = order; $value = 'new data 222222'; There is such keys in table: order, prices, contacts. 开发者_JAVA百科Each of these updates well except the 'order'. Why?
ORDER
is a reserved word.
Use back ticks to escape the column name:
UPDATE static_pages SET `order` = ";
Don't forget the WHERE clause so that you can update only specific records.
UPDATE static_pages SET `order` = "
WHERE id = 12;
order is a keyword in SQL. protect it with quotes in your query.
Best option is to rename your 'order' field
If you can't, here's a possible solution:
$query = 'UPDATE someTable SET `'.$key.'` = "'.$value.'"';
Where is WHERE
Have to use WHERE clause with update buddy
use `around the key`
$query = "UPDATE `someTable` SET `$key` = '$value'";
You can encase the reserved word orders
into backticks '`' or rename the field.
精彩评论