I am trying to run multiple queries in my database using MySQLi. This is my code:
$stmt = $mysqli->prepare('SELECT password FROM `users` WHERE username=? LIMIT 1');
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->bind_result($hashedPass);
$stmt->fetch();
$pwdHasher = new PasswordHash(8, FALSE);
if(!$pwdHasher->CheckPassword($password, $hashedPass))
exit;
$stmt = $mysqli->prepare('SELECT u_id FROM `users` WHERE username=? LIMIT 1');
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->bind_result($u_id);
$stmt->fetch();
But when the code starts, I get this error:
Fatal error: Call to a member function bind_param() on a non-object in C:\wamp\www\ajax\login.php on line 42
I checked that the database fields exist, so this is not the case. The first query works, it just seems like the second one that doesn't. I myself executed the request in phpMyAdmin and successfully created the result set, so I really don't know what happened.
source
share