MySQL 错误 - “您的 SQL 语法有错误”

发布于 2024-12-29 19:04:12 字数 478 浏览 0 评论 0原文

我收到的错误消息:

您的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

辞慾 2025-01-05 19:04:12

使用反引号 ` 而不是引号 ' 来转义名称。引号是字符串分隔符。

$toq="INSERT INTO articles (`word`,`group`, `selfnote`) VALUES ('$ttle','$wrdr','$snote')";

Use backticks ` instead of quotes ' to escape names. Quotes are string delimiters.

$toq="INSERT INTO articles (`word`,`group`, `selfnote`) VALUES ('$ttle','$wrdr','$snote')";
北方的韩爷 2025-01-05 19:04:12

您已在字段名称上加上引号。这迫使 MySQL 将它们视为字符串,而不是字段名称 - 并且您无法插入字符串。

INSERT INTO articles (word, group, selfnote) VALUES (....);

是正确的语法。字段名称上允许的唯一引用类型是使用反引号来转义保留字字段,例如,

INSERT INTO articles (table, int, varchar)  ...

由于使用 3 个保留字而失败,但添加反引号

INSERT INTO articles (`table`, `int`, `varchar`)  ...

使它们可以作为字段名称接受。

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.

INSERT INTO articles (word, group, selfnote) VALUES (....);

is the correct syntax. The only quoting type allowed on field names is the use of backticks to escape reserved word fields, e.g.

INSERT INTO articles (table, int, varchar)  ...

would fail due to the use of 3 reserved words, but adding backticks

INSERT INTO articles (`table`, `int`, `varchar`)  ...

makes them acceptable as fieldnames.

西瓜 2025-01-05 19:04:12

您不应使用普通引号 ('') 引用列名称,而应使用反引号 (``)。

You shouldn't quote column names with normal quotes (''), rather, use backticks (``).

浴红衣 2025-01-05 19:04:12

您必须删除列名的引号或用反引号 (`) 替换列名的引号。由于“group”是关键字,因此必须使用反引号:

INSERT INTO articles (`word`, `group`, `selfnote`) VALUES (....);

You must remove or replace the quotes of the column names by backticks (`). Since "group" is a keyword, you have to use backticks:

INSERT INTO articles (`word`, `group`, `selfnote`) VALUES (....);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文