This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center




8年前关闭。




我正在尝试在 PHP 中创建一些基本的插入查询,但它不断向我抛出错误,但我真的不知道为什么,请你们看看有什么问题吗?
    mysql_query("
INSERT INTO itens (nome, data, cliente, link, desc, img) VALUES ($nome,$data,$cliente,$link,$desc,$img)
") or die(mysql_error());

更新

从 OP 的已删除答案中提取,代码现在是:
mysql_query("INSERT INTO itens (nome, data, cliente, link, `desc`, img)
VALUES ($nome,$data,$cliente,$link,$desc,$img)") or die(mysql_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 'kl,j)' at line 2

kl 和 j 是我在表单中插入的最后两件事。

最佳答案

DESC 是 MySQL 保留关键字,您应该使用 backtick 对其进行转义,例如

INSERT INTO itens (nome, data, cliente, link, `desc`, img)
VALUES ($nome,$data,$cliente,$link,$desc,$img)
  • MySQL Reserved Keyword

  • 您的查询容易受到 SQL Injection 的影响,请花时间阅读下面有关如何防止它的文章,
  • How can I prevent SQL injection in PHP?
  • 关于php - 简单插入查询中的语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13936776/

    10-11 03:20
    查看更多