I have searched thread after thread with this error and everyone's error conceptually boils down to a parameter missing or misspelled. I have probably spent collectively around 4-5 hours trying to find the solution. I specifically made an account for this problem.
This is the error:
ERROR: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Whatever is wrong, my professors are stumped as well. Anyway here are some snippets of my code:
NOTE: I set "location" equal to "todo-description"'s content because I have not formatted my HTML page with a location box yet.
SOLUTION: the hyphen in "due-date" is an illegal character.
$data = array(
'todo-name' => array('name' => 'Todo Item Name','value' => '', 'errors' =>array()),
'todo-list' => array('name' => 'Todo List', 'value' => '', 'errors' => array()),
'todo-due-date' => array('name' => 'Due Date', 'value' => '','errors' => array()),
'todo-location' => array('name' => 'Location', 'value' => '','errors' => array()),
'todo-priority' => array('name' => 'Priority', 'value' => '','errors' => array()),
'todo-description' => array('name' => 'Description', 'value' => '','errors' => array())
);
if($total_errors == 0)
{
$date = DATETIME::createFromFormat('m/d/Y', $data['todo-due-date']['value']);
$date = $date->format('Y-m-d');
$data['todo-due-date']['value'] = $date;
$query = "insert into todo_item(name, due_date, list, priority, location, description)
values(:name, :due-date, :list, :priority, :location, :description);";
$statement = $db->prepare($query);
try
{
$statement->execute(array(
'name' => $data['todo-name']['value'],
'due-date' => $data['todo-due-date']['value'],
'list' => $data['todo-list']['value'],
'priority' => $data['todo-priority']['value'],
'location' => $data['todo-description']['value'],
'description' => $data['todo-description']['value']
));
if($statement)
{
$position = $db->lastInsertId();
header("Location: item.php?id=$position");
}
}
catch(Exception $ex)
{
die("Could not execute query: {$ex->getMessage()}");
}
}
else
{
die('error');
}