Luke Harrison
Luke Harrison

Reputation: 19

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in (xxx) PDOStatement->execute()

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();
  }

Upvotes: 0

Views: 2131

Answers (1)

TheBritishAreComing
TheBritishAreComing

Reputation: 1727

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);

Upvotes: 1

Related Questions