一旦密码进入数据库,你不应该让用户看到他们的密码,因为它应该被加密。这里有一些代码可以帮助你做你想做的事。
HTML
<div id="displayPass"></div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Enter Your email: </label><input type="text" name="email"/>
<input type="submit" name="submit" value="Retrieve password"/>
</form>
PHP(应该放在头部)
<?php
include('config.php');
if (isset($_POST['submit'])) {
$emailcheck = $_POST['email'];
$checkit = mysql_query("SELECT password FROM user WHERE email ='$emailcheck'");
if (empty($checkit))
{
echo "<script type='text/javascript'>
var div = document.getElementById('displayPass');
div.innerHTML = 'You have entered the incorrect email.';
</script>";
}
else
{
$result = mysql_fetch_array($checkit);
$question = $result['email'];
echo "<script type='text/javascript'>
var div = document.getElementById('displayPass');
div.innerHTML = 'Your password is '".$question."';
</script>";
}
}
?>
但是你应该是这样的......
HTML(带有一些 php)
<?php
session_start();
<form action="checkEmail.php" method="post">
<label>Enter Your email: </label><input type="text" name="email"/>
<input type="submit" name="submit" value="Retrieve password"/>
<label><?php echo $_SESSION["errorMessage"]; ?></label>
</form>
?>
PHP (checkEmail.php)
<?php
session_start();
//query database to see if its a correct email address
if(//email is not corrent){
$_SESSION["errorMessage"] = "Invalid Email.";
header("Location: emailForm.php");
}
else {
header("Location: newPasswordForm.php");
}
?>
然后您创建一个新页面,用户可以在其中填写表单以更改其密码。
希望这可以帮助。