QUOTE(dilemmalurve @ 24 Jun, 2008 - 07:59 PM)

i'm trying to write a script to send users their password if forgotten but i seem to have a problem...can someone help me...
i get this error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/...... on line 16
and line 16 is:
CODE
$count=mysql_num_rows($result);
this is my codes:
CODE
<?
include('db.php'); // database connection details stored here
// value sent from form
$email_to=$_REQUEST['email_to'];
// retrieve password from table where e-mail = $email_to
$result= mysql_query ("SELECT USERNAME, EMAIL, PASSWORD FROM Membership WHERE EMAIL= '$email_to' ");
// if found this e-mail address, row must be 1 row
// keep value in variable name "$count"
$count=mysql_num_rows($result);
// compare if $count =1 row
if($count==1){
$rows=mysql_fetch_array($result);
// keep password in $your_password
$your_password=$rows['PASSWORD'];
$your_username = $rows['USER_NAME'];
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email_to;
// Your subject
$subject="Your password here";
// From
$header="from: PayPerConest <paypercontest.com>";
// Your message
$messages= "Hello $your_username\r\n";
$messages.= "Your password for login to our website \r\n";
$messages.="Your password is $your_password \r\n";
//$messages.="more message... \r\n";
// send email
$sentmail = mail($to,$subject,$messages,$header);
}
// else if $count not equal 1
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
echo "Your Password Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send password to your e-mail address";
}
?>
if there are any mistakes please point them out to me...and if possible the solution i smuch appreciated
CODE
$result= mysql_query ("SELECT USERNAME, EMAIL, PASSWORD FROM Membership WHERE EMAIL= '$email_to' ");
Your mysql_query did not have connection, it should be like this
CODE
mysql_query($Query, $Connection) or die(mysql_error());
where connection hold this string
CODE
$Connection = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
and other thing, it is best to exclude the php string from the SQL string
CODE
$result= mysql_query ("SELECT USERNAME, EMAIL, PASSWORD FROM Membership WHERE EMAIL= '".$email_to."' ",$Connection) or die(mysql_error());