MySQLi不插入md5哈希

时间:2014-04-16 17:57:26

标签: php mysql sql syntax-error

    $date       = date('Y-m-d');
    $key        = md5(uniqid(rand(), true));

    $title  = mysqli_escape_string($dbc, $title);
    $content    = mysqli_escape_string($dbc, $content);
    $author     = mysqli_escape_string($dbc, $author);

    $query  = "INSERT INTO fpdf (title, authorID, content, dateCreated, dateEdited, key)
                  VALUES ('$title', '$author', '$content', '$date', '$date', '$key')";


    $result     = mysqli_query($dbc, $query);
    if(!$result) {
        echo "Database fout opgetreden.<br>";
        printf("Error: %s\n", mysqli_error($dbc));
    }



//// mysqli_error()
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 'key) VALUES ('werwerwer', '3', 'wrtwerw', '2014-04-16', '2014-04-16', '' at line 1 

我要么长时间看这个,要么我疯了。如果我从插入中完全删除密钥,它可以正常工作。

`key` varchar(32) DEFAULT NULL

1 个答案:

答案 0 :(得分:1)

keyreserved keyword.如果您打算使用它,必须将其换成刻度线;

$query  = "INSERT INTO fpdf (title, authorID, content, dateCreated, dateEdited, `key`)
              VALUES ('$title', '$author', '$content', '$date', '$date', '$key')";