Computing.Net > Forums > Programming > Help with forgot password script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with forgot password script

Reply to Message Icon

Name: salchipapi
Date: October 11, 2005 at 05:37:26 Pacific
OS: Win XP
CPU/Ram: 1.2 AMD, 224 MB
Comment:

Hi, I'm looking for a forgot password script that would work with a existing login script that uses PHP and MYSQL I want members to be able to retrieve forgotten their password by typing their email address or username
in the form, sending a automatically email to them with their password a found similar script, but it keeps giving me error. here is the script


<?php
// MySQL Information.

$db_host = "localhost"; // Host, 99% of the time this is localhost.
$db_username = "username"; // Username here
$db_password = "password"; // Password here

$linkID = @mysql_connect("$db_host", "$db_username", "$db_password");

// query commands

mysql_select_db("login", $linkID) or die(mysql_error()); // Database here
$resultID = mysql_query("SELECT username FROM signup WHERE email = '$email'", $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 signup WHERE email = '$email'", $linkID) or die(mysql_error());

$row = mysql_fetch_array($resultID);
$passwordfromdb = $row[0];

// End of query commands
// Send Password to email

mail($email, "Your Password", "Password: $passwordfromdb", "FROM: webmaster@mysite.com");
echo "Your Password has been sent to $email ";

}


// End of Send Password to email

mysql_close($linkID);

?>


when I type in a email address I get the following errors


Notice: Undefined variable: email in C:\Program Files\Apache Group\Apache2\htdocs1\signup\forgotpassword.php on line 13
We're sorry, your Email does not appear to be in our database.

line: 13 is...

$resultID = mysql_query("SELECT username FROM signup WHERE email = '$email'", $linkID) or die(mysql_error());


what's causing the errors, and even when the email address is stored on the my database it still says it not what's causing the errors, and even when the email address is stored on the my database it still says it not can someone please help me out to get this script to work.




Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: October 11, 2005 at 08:10:58 Pacific
Reply:

Are you sure that the query is using the $email variable and not sending the literal string of "$email". You can do a quick test by doing the following:

Add these two lines just before line 13:

$queryString = "SELECT username FROM signup WHERE email = '$email'";
echo $queryString . "[br]";

Then change line 13 to:

$resultID = mysql_query($queryString, $linkID) or die(mysql_error());

Now you will see exactly what is being sent to MySQL. If the string "$email" is being sent in the query instead of the variable value, you can modify the query as follows:

$queryString = "SELECT username FROM signup WHERE email = '".$email."'";

Michael J


0

Response Number 2
Name: salchipapi
Date: October 11, 2005 at 09:05:14 Pacific
Reply:

I can't to get it working, it seems like it's not sending anything, am not too good at PHP, do you now any other scripts I can use, or know where I can download them?
I just need a simple to fetch the username
and password from MYSQL database or from
.htaccess and send it to the user by email.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with forgot password script

Help with Script to process files www.computing.net/answers/programming/help-with-script-to-process-files/14989.html

Need help with WinXP batch script www.computing.net/answers/programming/need-help-with-winxp-batch-script/13165.html

Help with Assignment www.computing.net/answers/programming/help-with-assignment/18340.html