无法将用户添加到数据库,不匹配错误? '{ “errorInfo中”:[ “HY093”,0]}'

时间:2015-06-16 13:30:20

标签: php pdo

我无法弄清楚为什么这仍然给我一个PDO错误。我对php比较新,所以任何帮助都会很好。

    $query = "INSERT INTO users (userID, email, password, fName, lName, dob,
 online, verified, lastLogedIn, gender) VALUES (:id ,:email, :pass, :fn, :ln,
 dob, :online, :verified, :lli, :gender )";

$queryParams = array(
    ':id' => 0,
    ':email' => $_POST['email'],
    ':pass' => $_POST['password'],
    ':fn' => $_POST['firstName'],
    ':ln' => $_POST[':lastName'],
    ':dob' => $_POST[':dob'],
    ':online' => $online,
    ':verified' => $verified,
    ':lli' => $lli,
    ':gender' => $gender
);

try{

    $stmt = $db->prepare($query);
    $result = $stmt->execute($queryParams);
    var_dump($result->errorCode());

}catch(PDOException $ex){
    $response["success"] = 0;
    $response["message"] = "Database Error. failed to add user to database";
    echo '<pre>';
    print_r($result);
    echo '</pre>';
    die(json_encode($ex));
}

我的代码不断弹出这个错误,我知道这意味着查询和数据库不匹配,但我无法弄清楚在哪里。

3 个答案:

答案 0 :(得分:3)

你在dob中省略:,改为:

$query = "INSERT INTO users (userID, email, password, fName, lName, dob, online, verified, lastLogedIn, gender) VALUES (:id ,:email, :pass, :fn, :ln, :dob, :online, :verified, :lli, :gender )";

答案 1 :(得分:3)

您忘记了dob参数的冒号。

(:id ,:email, :pass, :fn, :ln, :dob, :online, :verified, :lli, :gender
                               ^

答案 2 :(得分:3)

:

之前遗失dob
"INSERT INTO users (userID, email, password, fName, lName, dob, 
online, verified, lastLogedIn, gender) VALUES (:id ,:email, :pass, 
:fn, :ln, :dob, :online, :verified, :lli, :gender )";
          ^^

$queryParams = array(
    ':id' => 0,
    ':email' => $_POST['email'],
    ':pass' => $_POST['password'],
    ':fn' => $_POST['firstName'],
    ':ln' => $_POST[':lastName'],//might be typo 
    ':dob' => $_POST[':dob'],// might be typo
    ':online' => $online,
    ':verified' => $verified,
    ':lli' => $lli,
    ':gender' => $gender
);

您的变量可能需要为

$_POST[':lastName'] ===&gt; $_POST['lastName']

$_POST[':dob'] ===&gt; $_POST['dob']

删除了那些额外的冒号