0

我目前正在关注 PHP 教程,并且我有以下代码::

$sql = "insert into practice (title, synopsis, genre, release, score, poster) 
        values('{$title}','{$synopsis}','{$genre}','{$release}','{$score}','{$poster}')";

if ($result = $mysqli->query($sql)) {
    // movie successfully added
    // redirect to index.php
    header("Location: index.html");
    exit;
}
elseif ($mysqli->connect_errno) {
    // there was a database error when inserting
    printf("Insert failed: %s\n", $mysqli->error);
}
else {
    printf("Sorry this isn't working! Insert failed: %s\n", $mysqli->error);
}

我目前收到的错误是“对不起,这不起作用......” mysqli 错误只是说明:

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 'release, score, poster) values ('fa','f','ff','ff','ff','ff')' at line 1.

我是一个完全的新手,所以我对语法错误实际上可能是什么感到有点迷茫。感谢您提前提供任何帮助

4

3 回答 3

8

releaseMySql 5.1中的保留关键字

您需要用反引号封装

$sql = "insert into practice (title, synopsis, genre, `release`, score, poster)  
        values('{$title}','{$synopsis}','{$genre}','{$release}','{$score}','{$poster}')"; 
于 2012-08-03T15:09:09.817 回答
2

“发布”似乎是mysql的一个关键字。

尝试用“`”转义关键字。

$sql = "insert into practice (title, synopsis, genre, `release`, score, poster) 
    values('{$title}','{$synopsis}','{$genre}','{$release}','{$score}','{$poster}')";
于 2012-08-03T15:09:53.980 回答
2

它说语法问题从“发布”开始。由于它看起来不像语法错误,因此它可能是一个保留字。请参阅http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

于 2012-08-03T15:09:57.930 回答