MySQL 错误 - “您的 SQL 语法有错误”
我收到的错误消息:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的 ''word','group','selfnote') VALUES ('item','a','note to self')' 附近使用的正确语法
PHP代码是:
$toq="INSERT INTO articles ('word','group','selfnote')
VALUES ('$ttle','$wrdr','$snote')";
我试图找到解决方案,但它们似乎没有像回显那样工作:
INSERT INTO articles ('word','group','selfnote')
VALUES ('item','a','note to self')
这对我来说似乎很好。问题是什么?
The error message I got:
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 ''word','group','selfnote') VALUES ('item','a','note to self')' at line 1
The PHP code is:
$toq="INSERT INTO articles ('word','group','selfnote')
VALUES ('$ttle','$wrdr','$snote')";
I was trying to find solutins, but they didn't seem to work as echoing gives:
INSERT INTO articles ('word','group','selfnote')
VALUES ('item','a','note to self')
which seems nice to me. What is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用反引号
`
而不是引号'
来转义名称。引号是字符串分隔符。Use backticks
`
instead of quotes'
to escape names. Quotes are string delimiters.您已在字段名称上加上引号。这迫使 MySQL 将它们视为字符串,而不是字段名称 - 并且您无法插入字符串。
是正确的语法。字段名称上允许的唯一引用类型是使用反引号来转义保留字字段,例如,
由于使用 3 个保留字而失败,但添加反引号
使它们可以作为字段名称接受。
You've put quotes on your field names. That forces MySQL to treat them as strings, not field names - and you can't insert into strings.
is the correct syntax. The only quoting type allowed on field names is the use of backticks to escape reserved word fields, e.g.
would fail due to the use of 3 reserved words, but adding backticks
makes them acceptable as fieldnames.
您不应使用普通引号 (
''
) 引用列名称,而应使用反引号 (``
)。You shouldn't quote column names with normal quotes (
''
), rather, use backticks (``
).您必须删除列名的引号或用反引号 (`) 替换列名的引号。由于“group”是关键字,因此必须使用反引号:
You must remove or replace the quotes of the column names by backticks (`). Since "group" is a keyword, you have to use backticks: