Monil Shah Monil Shah - 1 year ago 117
PHP Question

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Below is my code, I am not able to resolve this error. Any help is appreciated. I am trying to update a table in my database.

public function updateUnit($params){
$user = 'monil';
$password = 'Masters123';
$dbh = new \PDO('mysql:host=;dbname=tcsdb', $user, $password);

$task=array(':UnitCode'=>$params['UnitCode'],':UnitDescription'=>$params['UnitDescription'] ,
':UnitName'=>$params['UnitName'], ':UnitID'=>$params['UnitID']);
echo $params['UnitID'];

$sth = $dbh->prepare('UPDATE unit SET UnitCode = :UnitCode,'
. 'UnitDescription = :UnitDescription,UnitName = :UnitName WHERE UnitId=:UnitId');

return true;

Answer Source

:UnitID != :UnitId

Parameters are case-sensitive.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download