Forgot Password Not Sending Result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ProductManager
Forum Newbie
Posts: 6
Joined: Mon May 11, 2009 10:29 am

Forgot Password Not Sending Result

Post 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);
?>
Last edited by Benjamin on Tue May 12, 2009 11:33 am, edited 1 time in total.
Reason: Changed code type from text to php.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Forgot Password Not Sending Result

Post by divito »

On a quick glance, you assign $myemail, but use $email in the second query.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: Forgot Password Not Sending Result

Post 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?
ProductManager
Forum Newbie
Posts: 6
Joined: Mon May 11, 2009 10:29 am

Re: Forgot Password Not Sending Result

Post 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!
Post Reply