In the following code, I run two queries, one to pull the first and last names of a user from the database, and a second to write to a different field in the same entry in the database. The first query produces no results (and if I were to uncomment the $rowCount line and the line below, the script would abort there 100% of the time). The second query works perfectly.
Anyone have a theory about why?
$db = new mysqli($db_host, $db_user, $db_pass, $db_name, $db_port);
$user = get_post_var('email');
$user = preg_replace('/[^A-Za-z0-9@._-]/', '', $user);
$code = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
($stmt = $db->prepare('select first, last from users where user = ?'));
$stmt->bind_param('s', $user);
$stmt->execute();
$stmt->bind_result($first,$last);
//$rowCount = mysqli_num_rows($stmt);
//if($rowCount == 0) { fail("19","forgot"); } else {}
$stmt->close();
($stmt = $db->prepare('update users set reset = ? where user = ?'));
$stmt->bind_param('ss', $code, $user);
$stmt->execute();
$stmt->close();
mail( "$user", "Example.org Password Reset Code", "Dear $first $last,\n\n Please visit the following url to reset your password:\n http://www.example.org/reset.php?c=$code\n\nSincerely,\nSender", "From: noreply@example.org" );
fail('18',"forgot");
$db->close();