gpt4 book ai didi

php - 在 null/while 更新查询时调用成员函数 bind_param()

转载 作者:行者123 更新时间:2023-11-29 06:14:52 25 4
gpt4 key购买 nike

在我尝试了很多在 Google 和 stackoverflow 上找到的东西后,我无法解决我的问题。所以我决定问问社区。

这是我获取帖子表单的 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

我希望有人能发现我的错误,因为我自己找不到。 :/非常感谢每条有用的评论。

最佳答案

你误解了错误信息...

变量 $ustmt 可能为空,您不能对其调用函数 bind_param()。似乎是因为 $conn->prepare() 发出了警告并且似乎没有正确执行。

也许你应该稍微扩展你的 if 子句:

if(isset($ustmt) && $ustmt !== FALSE) 

关于php - 在 null/while 更新查询时调用成员函数 bind_param(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36429195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com