我想使用html表单将密码重置为哈希md5密码。我将包括我的所有代码。当我提交表格时,我得到一个空白的屏幕。我是初学者所以请记住这一点。我检查myphpadmin并且哈希密码没有改变。
<html>
<head><title> Administrator reset password page</title></head>
<body>
<form action="forgotpass.php" method="post">
<table>
<tr><td>User Name:</td><td><input type="text" name="password" /></td></tr>
<tr><td>Password:</td><td><input type="text" name="user" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Reset Password"/></td> </tr>
</table>
</form>
</body>
</html>
<?php
include "connect.php"
$tmpPass = $_POST['password'];
$tmpuser= $_POST['user'];
$tmpPass = md5($tmpPass);
$sql = mysql_query("UPDATE employee set pass = $tmpPass WHERE usr = $tmpuser");
// Performs the $sql query on the server to insert the values
if ($conn->query($sql) === TRUE) {
echo 'Password Has Been Reset Successfully';
/*
$email_message.= "Hello ";
$email_message.= "User with username: " .$tmpUser. "\n";
$email_message.= "Your New password: " .$_POST['password']. "\n";
$email_to = "registration@joshuamoorehead.com";
$email_subject = "Registration";
*/
else {
echo 'Error: '. $conn->error;
}
$conn->close();
?>
答案 0 :(得分:0)
您的字符串值缺少引号:
$sql = mysql_query("UPDATE employee set pass = '$tmpPass' WHERE usr = '$tmpuser'");
另外,为什么第二次运行查询?
// Performs the $sql query on the server to insert the values
if ($conn->query($sql) === TRUE) { // <-- HERE
echo 'Password Has Been Reset Successfully';
您的$sql
变量将包含查询的布尔结果,您需要检查该变量是否为真,而不是再次运行查询:
if($sql === true) {
echo 'Password Has Been Reset Successfully';