Welcome to WebmasterWorld Guest from 54.205.119.93

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Forgot Password Script

Can't get it to work...

   
12:00 am on Nov 26, 2005 (gmt 0)

10+ Year Member



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

Thanks,
Senmar

<?php

// allows user to reset password, if forgotten.
require_once ('config.inc');
include_once('header.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.
exit();

} 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">
<fieldset>
<p><b>User Name:</b> <input type="text" name="username" size="20" maxlength="25" value="<?php if (isset($_POST['username'])) echo $_POST['username'];?>" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Reset My Password" /></div>
</form><!-- End of Form -->

<?php
include ('footer.inc'); // Include the HTML footer.
?>

8:52 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

Tim

9:03 pm on Nov 26, 2005 (gmt 0)

10+ Year Member



misread post
12:35 pm on Nov 27, 2005 (gmt 0)

10+ Year Member



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?