I have a simple "lost password" form, with only two fields:
user and email address
The prefered piece to use in the query is the username, so I want to search the database for a match on that before I search on the email addy. Here' what I've got so far:
$user=$HTTP_POST_VARS["user"];
$email=$HTTP_POST_VARS["email"];
//CONNECT
mysql_connect (localhost, "user", "password");
mysql_select_db ("database");
//LOOK AT EITHER THE USERNAME OR PASSWORD
if (!empty($user)){
$result= mysql_query ("SELECT * FROM cal_users WHERE (username)=".$user);
} else {
$result= mysql_query ("SELECT * FROM cal_users WHERE (email)=".$email);
}
//set up the values
if ($row = mysql_fetch_array($result)) { //LINE 16
$klump = $row["email"];
$Subject = "AZRC forgotten password";
$Body = "You requested that this information be sent to you, for the AZ Rock Calendar.\n\nYou username is: ".$row["username"]."\n\nYour password is: ".$row["password"]."\n\n\nRock n Roll.";
//SEND THE ANNOUCNEMENT
mail("$klump","$Subject", "$Body","From: [email]foo@foo.com[/email]\nReply-To: [email]foo@foo.com[/email]");
//notify the user that an email was sent
print "<link href=\"../includes/cal-styles.css\" rel=\"stylesheet\" type=\"text/css\">";
print "<span class=\"text\">We have sent you an email with the username and password.<br><br><a href=\"javascript:window.close()\">Click here to close this window.</a></span>";
} else { print "Couldn't find anything for you."
}
The error I'm getting is "Supplied argument is not a valid MySQL result resource" on line 16 (which I noted in the code).
Its probably simple, but I can't see what I'm doing wrong.
Any ideas?
Thanks.