0
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 '' at line 1' in C:\xampp\htdocs\recover\recover.php:47 Stack trace: #0 C:\xampp\htdocs\recover\recover.php(47): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\recover\recover.php on line 47

这是我的代码:

// This checks if variabes are not empty, and if username is less than 11 characters long.
if (!empty($username) && !empty($password) && !empty($message) && strlen($username) < 11) {

    // Shortcut for our ID generator function.
    $ID = generateID();

    // Now lets insert (register the account) these datas to our database.
    $insert = $connect->prepare("INSERT INTO users (username, password, message, date, time, id) VALUES (:username, :password, :message, CURDATE(), CURTIME(), :id");

    // Executing in array, because if we binded all these variables, it would look very bad.
    $insert->execute(array(
        ':username' => $username,       
        ':password' => $password, 
        ':message' => $message, 
        ':id' => $ID
    ));

    if (!$insert->execute()) {
        print_r($insert->errorInfo());
    }       
}

我几乎是 PHP 新手,很多人告诉我在 mysql_ 过时之前开始使用 PDO。

所以我开始了,这似乎真的很难。试图习惯它。

我做错了什么?谢谢!

4

2 回答 2

3

VALUES 没有右括号。

于 2013-03-22T01:41:29.360 回答
2

和是date关键字time。请使用反引号将它们转义。


您缺少VALUES子句的括号。


prepare声明应该是:

$insert = $connect->prepare(
    "INSERT INTO users ( username, password, message, `date`, `time`, id )
        VALUES( :username, :password, :message, CURDATE(), CURTIME(), :id )"
);
于 2013-03-22T01:41:13.340 回答