Page 1 of 1

Forgotten password

Posted: Fri Nov 28, 2003 8:29 am
by Wldrumstcs
Ok, my next question is about making a forgotten password page. I have made it and what I want it to do is to take the email they sent in and get the corresponding password for it. My DB info is:
Table: members
3 Rows: id, email, password

Here is my script, tell me what's wrong please:

if ($submit) {

mysql_connect("localhost","username","password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("DB name") or die ("Unable to select requested database.");

$sql_email_check = mysql_query("SELECT password FROM members WHERE email='$email'");
$password = mysql_num_rows($sql_email_check);
if ($email == ""){
echo '<p align="center">Sorry, the form was left blank!</p>';
} else {
$sql_email_check = mysql_query("SELECT email FROM members WHERE email='$email'");
$email_check = mysql_num_rows($sql_email_check);

if($email_check > 0){
$to = $email;
$subject = "subject";
$message = "We have received your notice of a forgotten password. Here is your password:

Email: $email
Password: $password

If you have any questions/comments, don't hesitate to ask our staff!

Thanks!

This is an automated response, please do not reply!";

mail($to, $subject, $message, "From: dave_young@ameritech.net");
echo '<head><meta http-equiv="refresh" content="1;URL=index.php"></head><b><p>An email has been sent to you containing your password!</b></p><center>';
} else {
echo '<p><font color="#FF0000">That email address is not registered with TidBitFacts.com!</font></p><center>';
}}}
?>

Posted: Fri Nov 28, 2003 10:24 am
by JayBird
what error (if any) are you getting?

Posted: Fri Nov 28, 2003 11:33 am
by Wldrumstcs
I am not getting an error message, its just that that code isnt sending the corresponding password to the person's email address, it instead sends the number '1' which isn't the ID either. I dont know what that number is...

Posted: Fri Nov 28, 2003 11:47 am
by Weirdan
It's because you do not send the password to user. Instead you send count of users with the particular email:

Code: Select all

//....skipped
$password = mysql_num_rows($sql_email_check);
//....skipped
"
....
Password: $password
....
"

Posted: Fri Nov 28, 2003 12:12 pm
by Wldrumstcs
So how would i fix the script then cuz you just repeated what i already have in my php

Posted: Fri Nov 28, 2003 1:35 pm
by Weirdan
No, I told you what was wrong with your script ;)

Code: Select all

//...skipped
list($password) = mysql_fetch_row($sql_email_check);
//....skipped