【问题标题】:You have an error in your SQL syntax; check the manual that corresponds and etc您的 SQL 语法有错误;检查相应的手册等
【发布时间】:2012-02-04 23:29:44
【问题描述】:

我快疯了,我想在东西表中插入一个值,但我得到了这个错误

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 'name,describe,price,picname) values ('dfg','dfgdf','2','hr')' at line 1

我的代码是:

mysql_query("insert into stuff(name,describe,price,picname) values ('dfg','dfgdf','2','hr')") or die("cannot execute the query" .mysql_error());

我能做什么?它浪费了我1个小时的工作! 谢谢

【问题讨论】:

  • 您是否尝试在stuff 和字段列表的左括号之间添加一个空格?
  • 这里放空格stuff (name,describe,price,picname)
  • 是的,但我得到了同样的错误!
  • describe 也是保留关键字
  • 请显示表'stuff'的定义。

标签: php mysql mysql-error-1064


【解决方案1】:
mysql_query("insert into stuff (`name`,`describe`,`price`,`picname`) values ('dfg','dfgdf','2','hr')") or die("cannot execute the query" .mysql_error());

由于describe 是保留字,因此请用反引号将您的列名括起来。

【讨论】:

  • 完全错过了,哈哈。 +1
  • +1。但最好不要使用保留字作为字段名
  • 或者更好的是,更改您的列名。这将使您的 SQL 更加通用。 (我太慢了
  • 请告诉我mysql保留的关键字是什么?
  • DESCRIBE保留
【解决方案2】:

是SQL报错,你可以复制这条sql语句,直接在My SQL中执行,查看一下。

问题可能出在 2 的单个 qoutes 中,因为它是数字。

mysql_query("insert into stuff(name,describe,price,picname) values ('dfg','dfgdf',2,'hr')") or die("cannot execute the query" .mysql_error());

【讨论】:

    【解决方案3】:

    DESCRIBE 是一个 Mysql 关键字。请参阅documentation

    【讨论】:

    • 请告诉我mysql保留的关键字是什么?
    • @user1178177 只需点击链接即可。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    相关资源
    最近更新 更多