[英]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: 我不会问我是否不确定我是否100%不知道为什么这不起作用,因此,在PHP中,我只是试图更新MySQL数据库中的值:
The field im updating - Name: read - Type: tinyint - Length: 1 即时消息正在更新的字段-名称:读取-类型:tinyint-长度:1
Here is the PHP code: 这是PHP代码:
do_SQL("UPDATE messages SET read=1 WHERE id='".$id."'");
do_SQL(“更新消息SET读取= 1,其中id ='”。$ id。“'”));
The do_SQL function is working for everything else, so it's something wrong with this statement. do_SQL函数可用于其他所有功能,因此此语句有问题。 I have tried putting 1 in '1' and it still didn't work.m The error is:
我尝试将1放在'1'中,但仍然无法正常工作。错误是:
You have an error in your SQL syntax;
您的SQL语法有误; 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
检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'read = 1 WHERE id ='1'附近使用
Thanks for reading! 谢谢阅读!
read
是MySQL中的一个关键字,因此您必须在不加引号的情况下使用它(带反引号):
do_SQL("UPDATE messages SET `read`=1 WHERE id='".$id."'");
read is probably a reserved word in MySQL. read可能是MySQL中的保留字。
Yep it is MySQL Reserved Words 是的,这是MySQL保留字
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. 不要引用$ id。 Let PHP do substitution in the string.
让PHP在字符串中进行替换。
do_SQL("UPDATE messages SET read=1 WHERE id=$id.");
没有转义字符。
do_SQL('UPDATE messages SET read=1 WHERE id=\''.$id.'\'');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.