gpt4 book ai didi

php - 让用户更改自己的密码?

转载 作者:行者123 更新时间:2023-12-02 07:39:00 25 4
gpt4 key购买 nike

我刚开始学习 php 和 sql,所以请放轻松,我知道我在某些地方会出错。我试图让用户登录并能够更改他们的密码。我尝试了一个脚本,我认为它应该可以工作,但我想我做错了什么,因为它只会链接到 php 功能页面,根本不会更改密码。这是我的脚本:

HTML 格式:

<form method="POST" action="includes/changepassword.php">
<p><input type="password" name="oldpasswd" id="oldpasswd" maxlength="30" placeholder="Old Password"></p>
<p><input type="password" name="newpsswd1" id="newpsswd1" maxlength="30" placeholder="New Password"></p>
<p><input type="password" name="newpsswd2" id="newpsswd2"maxlength="30" placeholder="Confirm Password"></p>
<input type="submit" name="submit" id="submit" value="change password">

changepassword.php 文件:

 <?php
require_once("session.php");
require_once("functions.php");
require('_config/connection.php');
function changepassword ($oldpasswd, $newpasswd1, $newpasswd2) {
/*
* RETURNS
* 0 - if password changed
* 1 - if new passwords are not equal
* 2 - if user authentification problems
*/


$oldpasswd = ($_POST['oldpasswd']);
$newpasswd1 = ($_POST['newpasswd1']);
$newpasswd1 = ($_POST['newpasswd2']);




if ($newpasswd1 != $newpasswd2) {
return 1;
}

//check user logged in changes OWN passwd
$sql = "SELECT password FROM ptb_users WHERE id = ".$_SESSION['user_id'];
$result = mysql_query($sql)or die('User not found: ' . mysql_error());

if (md5($oldpasswd)==$result) {

//Encrypt $emailpassword in MD5 format for the database
$md5_np=md5($newpasswd1);

// Make a safe query
$query = sprintf("UPDATE `ptb_users` SET `password` = '%s'
WHERE `id` = ".$_SESSION['user_id'],
mysql_real_escape_string($md5_np));

mysql_query($query)or die('Could not update password: ' . mysql_error());
return 0;
} else {
return 2;
}


}
?>

我做错了什么?

最佳答案

it will just link to the php function page and not change the password at all

您告诉 HTML 表单执行此操作:<form method="POST" action="includes/changepassword.php"> .但另一方面,您永远不会调用您的函数。

关于php - 让用户更改自己的密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13212797/

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