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!
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.
<?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.