dongxun1142
2014-03-28 13:36 阅读 16
已采纳

Mysqli错误,出了什么问题?

$con=mysqli_connect(....stuff.....);

Here is the main part:

$sql2="INSERT INTO keys
(id,forgotkey)
 VALUES 
 ( '1' , '3453' ) ";

if(!$result2=mysqli_query($con,$sql2)){
    echo mysqli_error($con);
}

I get this 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 'keys(id,forgotkey) VALUES ( '1' , '3453' )' at line 1

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    douqiao5440 douqiao5440 2014-03-28 13:43

    keys is a mysql reserved keyword so it intreprets it as command not as a table name.

    Change your table's name or use `keys` <= this is not a quotation mark.

    点赞 评论 复制链接分享
  • dtj88302 dtj88302 2014-03-28 13:42

    Keys is reserved keyword use backticks around it.

    Try that:

    $sql2="INSERT INTO `keys` (id,forgotkey) VALUES ('1' ,'3453') ";   
    

    Check keywords here http://dev.mysql.com/doc/refman/5.7/en/reserved-words.html

    点赞 评论 复制链接分享
  • douhan1992 douhan1992 2014-03-28 13:42

    Use backticks => ` around reserved words.

    $sql2="INSERT INTO `keys`
    (`id`,`forgotkey`)
     VALUES 
     ( '1' , '3453' ) ";
    
    if(!$result2=mysqli_query($con,$sql2)){
        echo mysqli_error($con);
    }
    
    点赞 评论 复制链接分享

相关推荐