I am using PDO prepared queries to search a student's table
The user can select what field/s they wish to search by - firstname, lastname, date of birth, gender, or any combination of these.
I am trying to build an array on the fly to be executed by the prepared statement.
e.g. if the user selects lastname and dob, how do I generate the following array?
array(':lastname' => $lastname, ':dob' => $dob);
If I add the values as per usual:
$my_array[] = "[:lastname] => $lastname";
$my_array[] = "[:dob] => $dob";
And execute the query:
$stmt = $db_conn->prepare($query);
$stmt->execute($my_array);
I get an error:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\htdocs\pdo\students\search.php on line 67
Any suggestions gratefully received
$queryas well - Masivuye Cokile$my_array[':lastname'] = $lastname;and$my_array[':dob'] = $dob;- Tony