简体   繁体   中英

What's wrong with this SQL UPDATE query?

I wouldn't ask if i wasn't sure that i have 100% no idea why this isn't working, so, in PHP i'm simply trying to update a value in the MySQL database:

The field im updating - Name: read - Type: tinyint - Length: 1

Here is the PHP code:

do_SQL("UPDATE messages SET read=1 WHERE id='".$id."'");

The do_SQL function is working for everything else, so it's something wrong with this statement. I have tried putting 1 in '1' and it still didn't work.m The error is:

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 'read=1 WHERE id='1'' at line 1

Thanks for reading!

read是MySQL中的一个关键字,因此您必须在不加引号的情况下使用它(带反引号):

do_SQL("UPDATE messages SET `read`=1 WHERE id='".$id."'");

read is probably a reserved word in MySQL.

Yep it is MySQL Reserved Words

Next time check that list before creating a column with a name that's likely to be used already by the database system.

如果id是数字,请尝试删除引号:

do_SQL("UPDATE messages SET `read` = 1 WHERE id = ".$id);

Don't quote $id. Let PHP do substitution in the string.

 do_SQL("UPDATE messages SET read=1 WHERE id=$id.");

没有转义字符。

do_SQL('UPDATE messages SET read=1 WHERE id=\''.$id.'\'');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM