Forgotten password

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
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Forgotten password

Post 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>';
}}}
?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what error (if any) are you getting?
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post 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...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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
....
"
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

So how would i fix the script then cuz you just repeated what i already have in my php
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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