I am working on a little project and I can't seem to get one of my PDO insert querys to work.
I get the error message:
PHP Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /home/photobay/public_html/friendcon/register.php:24
And here is my code:
$datetime = htmlspecialchars(stripslashes(@$_POST['datetime']));
$fname = htmlspecialchars(stripslashes(ucfirst(@$_POST['first-name'])));
$lname = htmlspecialchars(stripslashes(ucfirst(@$_POST['last-name'])));
$email = htmlspecialchars(stripslashes(@$_POST['email']));
$password = htmlspecialchars(stripslashes(@$_POST['password']));
$gender = htmlspecialchars(stripslashes(@$_POST['gender']));
$password = password_hash($password, PASSWORD_BCRYPT);
$stmt = $db->prepare("INSERT INTO `users` (`id`, `first-name`, `last-name`, `email`, `password`, `gender`, `datetime`) VALUES (:id, :first-name, :last-name, :email, :password, :gender, :datetime)");
$stmt->execute(array(
':id' => null,
':first-name' => $fname,
':last-name' => $lname,
':email' => $email,
':password' => $password,
':gender' => $gender,
':datetime' => $datetime
));
$insertId = $db->lastInsertId();
I have checked and all the parameters are in there, I have 7 fields in my database and there are 7 parameters defined.
I am lost, I can't figure out what's wrong. Note: I am a beginner to PDO, and I am using PHP 7 if that helps