在下面的代码中,我运行了两个查询,一个是从数据库中提取用户的名字和姓氏,另一个是写入数据库中同一条目中的不同字段。第一个查询没有产生任何结果(如果我取消注释 $rowCount 行和下面的行,脚本将在 100% 的时间中中止)。第二个查询完美运行。
任何人都有关于为什么的理论?
$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();