The following code is producing the error: SQLSTATE[HY093]: Invalid parameter number
if (!$errFlag) {
//Get variables from POST
$values = array (
$_POST['studentLast'],
$_POST['studentFirst'],
$_POST['studentGradeID'],
$_POST['studentHRID'],
$_POST['studentTeamID'],
$_POST['studentParents'],
$_POST['studentAddress'],
$_POST['studentCity'],
$_POST['studentST'],
$_POST['studentZIP'],
$_POST['studentPhone1'],
$_POST['studentPhone2'],
$_POST['studentEmail1'],
$_POST['studentEmail2'],
);
//INSERT as a new row into the students database
try {
$userdb = userConnect();
$stmt = $userdb->prepare('
INSERT INTO
students (
studentStatus,
studentLast,
studentFirst,
studentGradeID,
studentHRID,
studentTeamID,
studentParents,
studentAddress,
studentCity,
studentST,
studentZIP,
studentPhone1,
studentPhone2,
studentEmail1,
studentEmail2
)
VALUES (
"active",
:studentLast,
:studentFirst,
:studentGradeID,
:studentHRID,
:studentTeamID,
:studentParents,
:studentAddress,
:studentCity,
:studentST,
:studentZIP,
:studentPhone1,
:studentPhone2,
:studentEmail1,
:studentEmail2
)
');
$stmt->execute($values);
} catch(PDOException $e) {
echo $e->getMessage();
die();
}
}
I found several users on Stack Overflow had the same issue, and the answers to their questions led me to believe that this error is caused when the number of parameters does not match the number of values. However, in the case of the code above, I have 14 parameters and 14 values. I am not sure, based on what I have read, why this is failing.
I am very new to PHP, and EXTREMELY new to PDO (I decided this week to refactor all of my work on this project, as I had been writing everything using mysqli, and felt that PDO might be a better option).
Any help would be greatly appreciated. Thanks!