homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Forgot Password Script
Can't get it to work...

10+ Year Member

Msg#: 10925 posted 12:00 am on Nov 26, 2005 (gmt 0)

Hi All,

I am trying to get this script to work. I have created a small Members Only section of the web site. All my scripts work, the register, login/logout, change-password..etc. The "Forgotten Password" script doesn't work. I put the
line below in the check where the error is located,

echo $query."<br>";
$result =@mysql_query($query) or die
(mysql_errno().": ".mysql_error()."<br>");

but the page remained blank after pressing the submit button. Help please...



// allows user to reset password, if forgotten.
require_once ('config.inc');

$page_title = "Forgot Your Password";
if (isset($_POST['submit'])) {

require_once ('connect.php');

if (empty($_POST['username'])) {
$u = FALSE;
echo '<p><font color="red" size="+1">You forgot to enter your username!</font></p>';
} else {
$u = escape_data($_POST['username']);

// Check for the existence of that username.
$query = "SELECT members_id, email FROM table WHERE username='$u'";

echo $query."<br>";
$result =@mysql_query($query) or die (mysql_errno().": ".mysql_error()."<br>");

$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) {
$mid = $row[0];
$email = $row[1];
} else {
echo '<p><font color=\"red\" size=\"+1\">The submitted username does not match those on file!</font></p>';
$u = FALSE;


if ($u) { // If everything's OK.

// Create a new, random password.
$p = substr (MD5(uniqid(rand(),1)), 3, 10);

// Make the query.
$query = "UPDATE table SET password=PASSWORD('$p') WHERE members_id='$mid'";
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.

// Send an email.
$body = "Your password to log into website has been temporarily changed to '$p'. Please log-in using this password and your username. At that time you may change your password to something more familiar.";
mail ($email, 'Your temporary password.', $body, 'From: admin.org@your.com');
echo '<h3>Your password has been changed. You will receive the new, temporary password at the email address with which you registered. Once you have logged in with this password, you may change it by clicking on the "Change Password" link.</h3>';
include ('footer.inc'); // Include the HTML footer.

} else { // If it did not run OK.

// Send a message to the error log, if desired.
$message = '<p><font color="red" size="+1">Your password could not be changed due to a system error. We apologize for any inconvenience.</font></p>';

mysql_close(); // Close the database connection.

} else { // Failed the validation test.
echo '<p><font color="red" size="+1">Please try again.</font></p>';


<h1>Reset Your Password</h1>
<p>Enter your username below and your password will be reset.</p>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<p><b>User Name:</b> <input type="text" name="username" size="20" maxlength="25" value="<?php if (isset($_POST['username'])) echo $_POST['username'];?>" /></p>
<div align="center"><input type="submit" name="submit" value="Reset My Password" /></div>
</form><!-- End of Form -->

include ('footer.inc'); // Include the HTML footer.



WebmasterWorld Senior Member 10+ Year Member

Msg#: 10925 posted 8:52 pm on Nov 26, 2005 (gmt 0)

Well I've looked this over and can't see any problem. This is usually where I start putting in little echo statements to debug things because obviously it's ending up somewhere where you don't think it should.



10+ Year Member

Msg#: 10925 posted 9:03 pm on Nov 26, 2005 (gmt 0)

misread post


10+ Year Member

Msg#: 10925 posted 12:35 pm on Nov 27, 2005 (gmt 0)

take the @'s out when debuging and add some more echos further up,
whats in the require_once ('connect.php') file?
does it contain anything?
is the error there?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved