[英]PHP/MYSQL Syntax error
Could you help me figure out what could be wrong with this line? 您能帮我弄清楚这行有什么问题吗?
$sql45="UPDATE invite_keys SET use=$num WHERE key=$getkey LIMIT 1 ";
I did some error checking and was able to determine that the above line has incorrect syntax, I just cannot figure out what exactly is causing it to fail. 我进行了一些错误检查,并能够确定上述行的语法不正确,我只是无法弄清楚是什么导致了失败。 Does anyone know?
有人知道吗?
Output of error: MySQL Query failed with 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 'use=1 WHERE key=2598131858 LIMIT 1' at line 1
Thank you for your help! 谢谢您的帮助!
USE and KEY are reserved words in MySQL and must be surrounded by backticks in your query: USE和KEY是MySQL中的保留字,在查询中必须用反引号括起来:
"UPDATE invite_keys SET `use` = $num WHERE `key` = $getkey LIMIT 1"
See the list of reserved words in the documentation . 请参阅文档中的保留字列表。
$sql45="UPDATE `invite_keys` SET `use`=" . $num . " WHERE `key`=" . $getkey . " LIMIT 1 ";
关键是-至少对字段始终使用``...
Mark's answer about the back ticks is right. 马克关于后壁s的答案是正确的。 Watch for using keywords in both SQL statements and PHP variables.
注意在SQL语句和PHP变量中使用关键字。 It's easy - and sometimes tempting - to do.
做起来很容易-有时很诱人。
A good thing to do when troubleshooting is to echo your SQL string so you can see it in full, that can give you a hint. 故障排除时要做的一件好事是回显您的SQL字符串,以便您可以完整地看到它,这可以给您提示。
If that doesn't help, try pasting into phpmysqladmin or another mySQL interface and see what error that gives. 如果那没有帮助,请尝试粘贴到phpmysqladmin或另一个mySQL接口中,看看会出现什么错误。 Sometimes it is more explanatory than what you see on a web page.
有时,它比您在网页上看到的更具解释性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.