在我尝试了很多我在谷歌上找到的东西之后,在这里,我无法解决我的问题。 所以我决定问社区。 p>
这是我获取帖子表单的PHP代码:
if (isset($_POST['submit'])) {
$firstPW = $_POST['password'];
$secondPW = $_POST['repassword'];
//DEBUG VARIABLES AREN'T NULL.
echo nl2br(trim($firstPW) . "\n" . trim($secondPW) . "\n" . $email . "\n" . trim($token) . "\n");
if ($firstPW == $secondPW) {
$pwunequal = FALSE;
$hashedpass = password_hash(trim($firstPW), PASSWORD_BCRYPT, array('cost' => 10));
// PASSWORD HASH ISN'T NULL
echo nl2br(trim($hashedpass) . "\n");
// $con is defined in another file which is required at the top.
$ustmt = $con->prepare("UPDATE users SET `Password` = ? WHERE Email = ?");
if ($ustmt !== FALSE) {
$ustmt->bind_param("ss", $hashedpass, $email);
$ustmt->execute();
echo "Successfully updated.";
$ustmt->close();
$con->close();
} else {
echo "NULL";
}
} else {
$pwunequal = TRUE;
}
}
当我提交表单时,我得到以下输出:
Value of $firstPW
Value of $secondPW
Value of $email (got email through $_GET[] before)
Value of $hashedpass
Warning: mysqli::prepare(): Couldn't fetch mysqli on line 49
Fatal error: Uncaught Error: Call to a member function bind_param() on null on line 51
以上都不是空的。
我的数据库设置:
The column "Password" = varchar(200), collation = utf8_general_ci, not null, default none
The column "Email" = varchar(200), collation = utf8_general_ci, not null, default none
我希望有人能发现我的错误,因为我自己无法找到它。 :/ 非常感谢每一条有用的评论。
答案 0 :(得分:2)
您误解了错误消息......
变量 $ ustmt problably为null,您无法在其上调用函数 bind_param()。似乎情况是 $ conn-> prepare()引发了一个警告,似乎没有正确执行。
也许你应该稍微扩展你的if子句:
if(isset($ustmt) && $ustmt !== FALSE)