gpt4 book ai didi

php - 在 PHP 和 mySQL 中更改用户密码

转载 作者:行者123 更新时间:2023-11-29 01:45:09 24 4
gpt4 key购买 nike

找到答案了!!

看了很久才找到答案!

只是简单地改变

$querynewpass = "UPDATE tz_members SET `pass`='".$_POST['$passwordnew1']."' WHERE usr='{$_SESSION['usr']}'";

到:

$querynewpass = "UPDATE tz_members SET `pass`='".md5($_POST['passwordnew1'])."' WHERE usr='{$_SESSION['usr']}'";

只是我错过的简单 md5!

问题:

我正在尝试使用他们输入当前密码和新密码的表单来更改用户密码。它应该检查 mySQL 数据库以查看他们输入的当前密码是否与他们登录的当前 session 用户匹配,然后将 mySQL 数据库更新为新密码。这是我到目前为止的脚本:

if($_POST['submit']=='Change')
{
// Checking whether the Password Change form has been submitted

$err = array();
// Will hold our errors


if(!$_POST['password1'] || !$_POST['passwordnew1'])
$err[] = 'All the fields must be filled in!';

if(!count($err))
{
$_POST['password1'] = mysql_real_escape_string($_POST['password1']);
$_POST['passwordnew1'] = mysql_real_escape_string($_POST['passwordnew1']);

// Escaping all input data

$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_SESSION['usr']}' AND pass='".md5($_POST['password1'])."'"));

if($row['usr'])
{
// If everything is OK change password

$querynewpass = "UPDATE user SET `password`='".$_POST['$passwordnew1']."' WHERE id='".$_SESSION['usr']."'";
$resultnewpass = mysql_query($querynewpass) or die(mysql_error());

}
else $err[]='Wrong Password To Start With!';
}

if($err)
$_SESSION['msg']['passwordchange-err'] = implode('<br />',$err);
// Save the error messages in the session

header("Location: index.php");
exit;
}

但出现错误“表‘databasename.user’不存在”我有一个登录和注册表单,可以使用此方法正常工作!

更新:我有一个数据库,它有一个名为 tz_members 的表,列是 id、pass、user、regIP 和 dt

我的 mysql 查询现在是:

$querynewpass = "UPDATE tz_members SET `pass`='".$_POST['$passwordnew1']."' WHERE usr='{$_SESSION['usr']}'";

再次更新添加表单代码供您查看:

    <!-- Pass Change Form -->
<form action="" method="post">
<?php

if($_SESSION['msg']['passwordchange-err'])
{
echo '<div class="err">'.$_SESSION['msg']['passwordchange-err'].'</div>';
unset($_SESSION['msg']['passwordchange-err']);
}

if($_SESSION['msg']['passwordchange-success'])
{
echo '<div class="success">'.$_SESSION['msg']['passwordchange-success'].'</div>';
unset($_SESSION['msg']['passwordchange-success']);
}
?>

<label class="grey" for="password1">Current Password:</label>
<input class="field" type="password" name="password1" id="password1" value="" size="23" />
<label class="grey" for="password">New Password:</label>
<input class="field" type="password" name="passwordnew1" id="passwordnew1" size="23" />
<input type="submit" name="submit" value="Change" class="bt_register" />
</form>

最佳答案

您在似乎与同一个表相关的两个查询中使用了两个不同的表(和列)。

检查您的架构并适当调整第二个查询。

第二个查询应该是这样的:

$querynewpass = "UPDATE tz_members SET `pass`='".md5($_POST['passwordnew1'])."' WHERE usr='{$_SESSION['usr']}'";

关于php - 在 PHP 和 mySQL 中更改用户密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8893332/

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