0

I need to update the mailcode in the users database. I created this code.

$statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$result = $statement->execute(array('email' => $email));
$user = $statement->fetch();

$mailcode = random_string();
$statement = $pdo->prepare("UPDATE users SET mailcode = :mailcode WHERE id = :userid");
$result = $statement->execute(array('mailcode' => sha1($mailcode), 'userid' => $user['id']));

I get this error below:

Error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

I have written another PHP code using the same code snippets. It works in the other code, but it doesn't work in this code. I have tried many different spellings, but it still doesn't work.

This is the other code: This code snippet works in my code, while the other code doesn't.

$passwordcode = random_string();
$statement = $pdo->prepare("UPDATE users SET passwordcode = :passwordcode, passwordcode_time = NOW() WHERE id = :userid");
$result = $statement->execute(array('passwordcode' => sha1($passwordcode), 'userid' => $user['id']));

Why doesn't the other code work?

I tried many different spellings, but it still doesn't work.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Hoppel
  • 1

0 Answers0