Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的重置密码系统给了我一个数据库错误_Php_Mysqli - Fatal编程技术网

Php 我的重置密码系统给了我一个数据库错误

Php 我的重置密码系统给了我一个数据库错误,php,mysqli,Php,Mysqli,我一直在尝试重新设置密码系统,代码如下: <?php ob_start(); include "includes/header.php"; include "includes/db.php"; //session_start(); include "includes/navigation.php"; if(isset($_GET['reset']) && isset($_GET['token'])) { $token = $_GET['token']; $stmt =

我一直在尝试重新设置密码系统,代码如下:

<?php  ob_start();
include "includes/header.php";
include "includes/db.php";
//session_start();
include "includes/navigation.php";

if(isset($_GET['reset']) && isset($_GET['token'])) {

$token = $_GET['token'];
$stmt = mysqli_prepare($connection, "SELECT username, user_email, token FROM users WHERE token=?");
mysqli_stmt_bind_param($stmt, "s", $token);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $username, $user_email, $token);
mysqli_stmt_fetch($stmt);
if(!empty($username)) {
if(isset($_POST['password']) && isset($_POST['confirmPassword']) && $_POST['password'] == $_POST['confirmPassword']) {
$password = $_POST['password'];
$hashedPassword = password_hash($password, PASSWORD_BCRYPT, array('cost'=>12));
echo $hashedPassword;
echo $user_email;

$stmt = mysqli_prepare($connection, "UPDATE users SET token= '', user_password= '{$hashedPassword}' WHERE user_email= ?");
mysqli_stmt_bind_param($stmt, "s", $user_email);
mysqli_stmt_execute($stmt);


}

} else {
  header("Location: index.php");
}
} else {
  header("Location: index.php");
}




?>

我已经修改了您的代码,并尽可能地记录了您出错的地方,以及为什么我的更正应该有效

<?php  ob_start();
include "includes/header.php";
include "includes/db.php";
//session_start();
include "includes/navigation.php";

if(isset($_GET['reset']) && isset($_GET['token'])) {

$token = $_GET['token'];
//I have amended your query, you do not need to grab the token if the condition is that it is the same as something you already have, as $_GET['token'] AND $token will always be the same.
$query = "SELECT username, user_email FROM users WHERE token = ?");
$stmt = $connection->prepare($query);
$stmt->bind_param("s", $_GET['token']);
$stmt->execute();
$stmt->bind_result($username, $user_email);
$stmt->fetch();
$stmt->close(); // You did not close your query connection. 
// To use a new query you must first close the previous one.

if(!empty($username)) {
if(isset($_POST['password']) && isset($_POST['confirmPassword']) && $_POST['password'] == $_POST['confirmPassword']) {
$password = $_POST['password'];
$hashedPassword = password_hash($password, PASSWORD_BCRYPT, array('cost'=>12));
echo $hashedPassword;
echo $user_email;

// Previously you tried to insert a PHP variable into a query, which is not possible
// in (and defeats the point of) prepared statements. Rather than put in $variable
// replace them with '?' . (not including quotation marks)
$query = "UPDATE users SET token = null, user_password = ? WHERE user_email = ?";
$stmt = $connection->prepare($query);
$stmt->bind_param("ss", $hashed_password, $user_email);
$stmt->execute();
$stmt->close();    

}

} else {
  header("Location: index.php");
}
} else {
  header("Location: index.php");
}

关闭您的语句。您尝试在活动连接上加载2个查询。要么释放结果,要么关闭语句,或者使连接的第二个实例变差。code>mysqli_stmt_bind_param()期望参数1是mysqli_stmt,给定布尔值
为什么
“{$hashedPassword}”
?在没有花括号的情况下尝试?
mysqli\u prepare
如果成功返回对象,或者如果发生错误,则返回对象。查看@Dorvalla的评论以获得提示。非常感谢您的支持。我明白你的意思了,回家后我会检查一下。它奏效了。只需关闭查询,一切都正常。非常感谢你。