Page 1 of 1

Forgot Password Not Sending Result

Posted: Tue May 12, 2009 8:05 am
by ProductManager
I have a forgot password page that is sending an email succesfully, but the resulting password is blank (even though there is a valid password in the record for the associated email address I am entering in the form). When I echo the $passwordfromdb, I also get no result. Any thoughts would be greatly appreciated.

Code: Select all

<?php
// MySQL Information.
$db_host = "localhost"; // Host, 99% of the time this is localhost.
$db_username = "User"; // Username here
$db_password = "Password"; // Password here
$linkID = @mysql_connect("$db_host", "$db_username", "$db_password");
// email sent from form 
$myemail=$_POST['email']; 
// query commands
mysql_select_db("laborchamp", $linkID) or die(mysql_error()); // Database here
$resultID = mysql_query("SELECT user FROM lcuser WHERE email = '$myemail'", $linkID) or die(mysql_error());
// End of query commands
// Check if Email is in database
$num_rows = mysql_num_rows($resultID); 
$row = mysql_fetch_array($resultID); 
$user_id = $row[0];
if ($user_id == "") {
print "We're sorry, your Email does not appear to be in our database.";
}
else {
// query commands
$resultID = mysql_query("SELECT Password FROM lcuser WHERE Email = '$email'", $linkID) or die(mysql_error());
$row = mysql_fetch_array($resultID); 
$passwordfromdb = $row['Password'];
// End of query commands
// Send Password to email
$subject = 'Your Password';
$headers = 'webmaster@test.com';
mail($myemail, $subject, $passwordfromdb, $headers); 
echo "Your Password has been sent to $myemail.";
}
// End of Send Password to email
mysql_close($linkID);
?>

Re: Forgot Password Not Sending Result

Posted: Tue May 12, 2009 12:51 pm
by divito
On a quick glance, you assign $myemail, but use $email in the second query.

Re: Forgot Password Not Sending Result

Posted: Tue May 12, 2009 7:13 pm
by ldougherty
Have you tried running this query directly in mySQL or in phpMyAdmin?

SELECT Password FROM lcuser WHERE Email = '$email';

Does it yield a result? If your variable $passwordfromdb is returning no value then $row['Password']; has no value.

Maybe you are returning more than 1 result from the database and you're pulling a blank password for the email?

Re: Forgot Password Not Sending Result

Posted: Wed May 13, 2009 6:56 am
by ProductManager
divito wrote:On a quick glance, you assign $myemail, but use $email in the second query.
Thanks Divito - that was all it was - simple oversight. Appreciate it!