I have a problem with my "password recover" script.
I have a form to fill in the email address on one page and when you submit it to go to the password recover page, I get an error ONLY when there are NO rows returned from the database and a "header already sent" error as well.
It only works when there is an email address match in the database. Then there are no errors and the re-direct works without problem.
This script works on other servers, but this problem is on Godaddy.com.
I wonder if someone could take a look at it and let me know if there is a way to go around it.
Again, there is only a problem when there is no match of email address in the database.
Here are part of the errors I get:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /home/content.......
Warning: Cannot modify header information - headers already sent by (output started at /home/content
...../find_password.php:32)
in /home/content...../find_password.php on line 48
FORM PAGE
<FORM METHOD="POST" ACTION="find_password.php">
<input name="email" type="text" />
<input type="submit" name="Submit" value="Submit" />
</FORM>
RECOVER PASSWORD PAGE
PHP Code:
<?php
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$email = clean($_POST['email']);
$QUERY = mysql_query("SELECT * FROM members WHERE email='$email'");
$ROWS = mysql_num_rows($QUERY);
$MyPsswd = mysql_result($QUERY,$I,"password");
$MyUser = mysql_result($QUERY,$I,"username");
if ($ROWS) {
ini_set("sendmail_from", "info@domain.com");
ini_set("SMTP", "mail.domain.com");
$address = $email;
$email2 = "info@domain.com";
$subject = "* * Login Details Recover * *";
$body = "Login Details Recover\r\n\r\nGreetings,\r\nHere are you login details. Contact us if you require any further assistance.\r\n\r\nPassword: $MyPsswd\nUser: $MyUser\n";
$mailsend = mail("$address","$subject","$body","From: Website Administrator <$email2>");
header("Location:success.php");
} else {
header("Location:email_error.php");
exit;
}
?>





Bookmarks