Hello everyone and thanks for helping me with my first post!
I am working on a new site and am new to PHP myself. I have already created a user registration and login / logout area. I want to now have a place where users can request to have their forgotten password emailed to them.
Ideally, the HTML form would tell the PHP script to use the entered username ( $username ) to log into the MySQL table 'users' and find the corresponding Email Address ( $email ) and Password ( $password). It would then use that email address so send the user their password.
I THOUGHT that I had the code correct to do this but all that happens is that the web page refreshes... and that is it. No password is mailed :-(
This is the snippet of code that I am using. Can ANYONE take a few minutes and fix it or tell me what is wrong or something?!
<?php
if(isset($_POST['remind_me'])) { // if form has been submitted
$sql = "SELECT password,email FROM users WHERE username='$username'";
$query = mysql_query($sql);
if ($result = mysql_fetch_array($query)) {
$thisPassword = $result[password];
$thisEmail = $result[email];
$message = "Your password is $thisPassword";
mail("$thisEmail", "Information you requested.", "$message", "From: [email]webmaster@domain.com[/email]\n");
}
} else {
?>
<form action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
<table width="590" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/spacer.gif" width="250" height="15"></td>
</tr>
<tr>
<td>Complete this form and your password will be sent to the Email address you used when you signed up.</td>
</tr>
<tr>
<td><img src="images/spacer.gif" width="250" height="15"></td>
</tr>
<tr>
<td>Username:</td>
</tr>
<tr>
<td>
<input type="text" name="username" maxlength="20" size="30">
</td>
</tr>
<tr>
<td><img src="images/spacer.gif" width="250" height="10"></td>
</tr>
<tr>
<td>
<input type="hidden" name="remind_me" value="1">
<input type="image" value="Submit" border="0" src="images/button_remind.gif" width="93" height="24">
</td>
</tr>
</table>
<br>
</form>
<?php
}
?>
Thanks everyone!
- Ham