Failed to add user to database, mismatch error? '{"ErrorInfo": ["HY093", 0]}'
I can't figure out why this is still giving me a PDO error. I am relatively new to php, so any help would be appreciated.
$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));
}
My code keeps throwing this error, I know it means there is a mismatch in the query and the database, but I can't figure out where.
+3
source to share
3 answers
Missing :
beforedob
"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
);
Perhaps your variable should be like
$_POST[':lastName']
===> $_POST['lastName']
$_POST[':dob']
===> $_POST['dob']
Extra colons removed
+3
source to share