我正在尝试制作一个简单的重置密码表单,用户输入其用户名,电子邮件地址,新密码并确认新密码。但是,当我运行页面时没有任何反应。下面是我正在使用的表单以及PHP脚本。
FORM:
<form method="POST" action="password.php">
<table>
<tr>
<td>Enter your Email</td>
<td><input type="text" size="60" name="email"></td>
</tr>
<tr>
<td>Enter your UserName</td>
<td><input type="text" size="30" name="username"></td>
</tr>
<tr>
<td>Enter your new password:</td>
<td><input type="password" size="30" name="newpassword"></td>
</tr>
<tr>
<td>Re-enter your new password:</td>
<td><input type="password" size="30" name="confirmnewpassword"></td>
</tr>
</table>
<p><input type="submit" value="Update Password">
</form>
PHP SCRIPT
<?php require_once('Connections/register.php'); ?>
<?php
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirmnewpassword = $_POST['confirmnewpassword'];
// Redirect links for when password reset is successful or not.
$MM_passwordResetSuccess = "password-updated.php";
$MM_passwordResetFailed = "reset-password.php";
$result = mysql_query("SELECT * FROM register WHERE
username='$username' AND email='$email'");
if(!$result)
{
echo "The username or email you entered does not exist";
}
if($password == $confirmnewpassword)
$sql=mysql_query("UPDATE register SET password='$password' where
username='$username' AND email='$email'");
if($sql)
{
header("Location: " . $MM_passwordResetSuccess );
//echo "Congratulations You have successfully changed your password";
}
else
{
header("Location: ". $MM_passwordResetFailed );
//echo "Passwords do not match";
}
?>
有人可以帮忙吗?
答案 0 :(得分:1)
您没有检查表单提交..
此外,您应该在输入字段中添加名称
像这样:
<p><input name="reset" type="submit" value="Update Password">
PHP文件:
<?php
if(isset($_POST['reset'])){
//Your php code
}
?>
答案 1 :(得分:1)
您的输入元素<td><input type="password" size="30" name="newpassword"></td>
名称为“newpassword”,但您只能尝试$password = $_POST['password']
- “密码”。
所以将其更改为$password = $_POST['newpassword'];
BUT :
1st:从不将普通密码存储到您的数据库中。使用password_hash()
和password_verify()
第二:使用准备好的陈述。现在这个剧本非常不安全
第3名:您还需要提供旧密码。
第四:你应该先检查你是否有价值,所以
if(!isset($_POST['email']) {
// show an error, exit script
echo "ERROR"
}
每个变量后的。否则你可能会收到错误(正如你现在所做的那样)
5:开启error_reporting(E_ALL);
答案 2 :(得分:0)
您可以按照以下方式修改标头:header("Location: password-updated.php" );
和header("Location: reset-password.php");
,因为它是使用标头功能的最简单方法。同时将$password = $_POST['password'];
更改为$password = $_POST['newpassword'];