You should never let the user see their password once it has entered the database because it should be encrypted. Here is some code that might help you do what you want.
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 (which should be placed in the head)
<?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>";
}
}
?>
But what you should is something like this...
HTML (with some 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");
}
?>
Then you create a new page where the user can fill out a form to change their password.
Hope this helps.