Could not fetch array because:
Posted: Wed Oct 18, 2006 2:37 pm
I have the error that is in the title when I test the following code with a username that isn't in the database. Can someone please tell me why and how I can fix it? Thanks in advance.
Code: Select all
require "config2.php";
$arrErrors = array();
// checking to see if the submit button has been pressed
if (isset($_POST['Submit'])) {
// checking to see if the username field is blank
if ($_POST ['username'] == '') {
// if username field is blank display an error
$arrErrors['username'] = 'Please enter your username.';
}
// if no errors send the password
if (count($arrErrors) == 0) {
// get the username from the form
$username = mysql_real_escape_string($_POST['username']);
// select the username, password and email address
$query = mysql_query("SELECT `username`, `password`, `email` FROM `users` WHERE `username`='$username'");
$check = mysql_num_rows($query);
$rows = mysql_fetch_array($query) or die ("Could not fetch array because: ".mysql_error());
if($check != 0) {
$password=$rows['password'];
$to=$rows['email'];
$subject="Your Barwonnp.com.au Password Retrieval";
$header="From: Camille Turner <camille.turner@bigpond.com>";
$messages="Dear $username \r\n";
$messages.="You are receiving this e-mail because you requested a password reminder from barwonnp.com.au. \r\n";
$messages.="As requested, please find below your password. \r\n";
$messages.="Your password: $password \r\n";
$messages.="Regards \r\n";
$messages.="Kevin Humphries \r\n";
$messages.="www.barwonnp.com.au \r\n";
$messages.="Please ensure that this password is not accessible by others, to ensure security of your information. \r\n";
$sentmail = mail($to,$subject,$messages,$header);
} else {
echo "Your username isn't in our database.";
}
if($sentmail){
header ('Location: password_sent.php');
} else {
echo "Cannot send password to your e-mail address.";
}
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}
mysql_close();