我已编写此代码来更新用户的密码,它似乎是根据回显发布,但在尝试登录时,新密码或旧密码都不起作用! 需要一手这个,这是代码:
if(isset($_POST['confirmReset'])){
$q = "SELECT * FROM user WHERE email = '".$_POST['email']."'";
$resObj = mysqli_query($conn, $q);
$rowcount=mysqli_num_rows($resObj);
//var_dump($rowcount);
if ($rowcount == 1) {
$q = "UPDATE user SET password = '".md5($password)."' WHERE email = '".$_POST['email']."'";
if (mysqli_query($conn, $q)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$rowcount=mysqli_num_rows($resObj);
} else {
}
var_dump($_POST);
}
答案 0 :(得分:0)
您必须定义$ password变量。
由于你的代码很精简,也许&#34; $ _POST [&#39; confirmReset&#39;]&#34;是包含密码的输入?
$password = $_POST['confirmReset'];
就像那样:
if(isset($_POST['confirmReset'])) {
$password = $_POST['confirmReset'];
// Following the code ...
答案 1 :(得分:0)
你在哪里获取$ password的价值?
if(isset($_POST['confirmReset'])){
$password = $_POST['password']; // Change this with the name of the POST variable.
$q = "SELECT * FROM user WHERE email = '".$_POST['email']."'";
$resObj = mysqli_query($conn, $q);
$rowcount=mysqli_num_rows($resObj);
//var_dump($rowcount);
if ($rowcount == 1) {
$q = "UPDATE user SET password = '".md5($password)."' WHERE email = '".$_POST['email']."'";
if (mysqli_query($conn, $q)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
$rowcount=mysqli_num_rows($resObj);
} else {
}
答案 2 :(得分:0)
要检查密码是否已更新,您可以使用:
mysqli_affected_rows()
这将为您提供更新的行数。
答案 3 :(得分:0)
你的md5加密是否适用于&amp;而不是使用那个可靠的
$v1 = $_POST['password'];
$v2 = md5($v1);
使用此$ v2更新sql查询中的密码
Update tb_name set password = '".$v2."' where email = '".$email."'