Home > database >  Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not def
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not def

Time:09-27

I've searched around on stack and I really can't find anything that fixes this error, I'm trying to update a registration key to say that it's used and which user it has been used by.

Here's the full error:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in D:\xampp\htdocs\core\private_keys.php:33 Stack trace: #0 D:\xampp\htdocs\core\private_keys.php(33): PDOStatement->execute() #1 D:\xampp\htdocs\register.php(36): PrivateKeys->update_key('13', '376732aa82cbb13...') #2 {main} thrown in D:\xampp\htdocs\core\private_keys.php on line 33

function update_key($id, $keyUsed){
    $update_statement = $this->pdo->prepare("UPDATE `private_key` SET `used` = :used, `user_id` = :used_by WHERE `key` = :keyText");

    $used_num = 1;
    $update_statement->bindParam(':used', $used_num, PDO::PARAM_INT);
    $update_statement->bindParam(':user', $id, PDO::PARAM_INT);
    $update_statement->bindParam(':keyText', $keyUsed, PDO::PARAM_STR);

    $update_statement->execute();
  }

CodePudding user response:

your statement has :used_by

   $update_statement = $this->pdo->prepare("UPDATE `private_key` SET `used` = :used, `user_id` = :used_by WHERE `key` = :keyText");

But your params is providing :user

   $update_statement->bindParam(':user', $id, PDO::PARAM_INT);
  •  Tags:  
  • php
  • Related