Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 117,165 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 2,512 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



error: mysql_num_rows(): supplied argument is not a valid MySQL result

 
Reply to this topicStart new topic

error: mysql_num_rows(): supplied argument is not a valid MySQL result, requesting password when forgotten

Ladydice
post 25 Jun, 2008 - 11:22 PM
Post #1


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 18


My Contributions


crazy.gif I'm facing a problem that i cant seem to solve...please so bare in mind that I'm a beginner and my codes might be a lil messy...

problem:
CODE
$count=mysql_num_rows($result);

error: mysql_num_rows(): supplied argument is not a valid MySQL result resource in

this is my full codes...if there any more errors please do tell me...in if possible could i have the solution...thank you... biggrin.gif

CODE


<?
include('db.php'); // database connection details stored here


// value sent from form
$email_to=$_REQUEST['email_to'];

//if($_REQUEST['email_to']) $email_to=$_REQUEST['email_to'];
//else die('Email does not have a value');


//// retrieve password from table where e-mail = $email_to(mark@phpeasystep.com)
$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);
//echo $count;

if (isset($result)){

$count=mysql_num_rows($result);
echo 'count = '.$count;
} else
{echo 'No result was returned';}


// 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";
}

?>
crazy.gif crazy.gif
User is offlineProfile CardPM

Go to the top of the page


no2pencil
post 25 Jun, 2008 - 11:29 PM
Post #2


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 5,388



Thanked 35 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


This looks like code I was helping someone else with... & you commented out the lines that perform error checking to assure that a value was given.

& If the value coming $_REQUEST['email_to'] is not present, then $email does not get set, & then when you perform your mysql select statement, & there is nothing in $email, $result does not get a value, & then finally since $result doesn't hold a vlaue, when it's passed to mysql_num_rows() & you get an error like error: "mysql_num_rows(): supplied argument is not a valid MySQL result resource in".

So uncomment the error checking & make sure you are working with valid data.
User is offlineProfile CardPM

Go to the top of the page

Ladydice
post 3 Jul, 2008 - 12:13 AM
Post #3


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 18


My Contributions


QUOTE(no2pencil @ 25 Jun, 2008 - 11:29 PM) *

This looks like code I was helping someone else with... & you commented out the lines that perform error checking to assure that a value was given.

& If the value coming $_REQUEST['email_to'] is not present, then $email does not get set, & then when you perform your mysql select statement, & there is nothing in $email, $result does not get a value, & then finally since $result doesn't hold a vlaue, when it's passed to mysql_num_rows() & you get an error like error: "mysql_num_rows(): supplied argument is not a valid MySQL result resource in".

So uncomment the error checking & make sure you are working with valid data.



you are right there is someone who posted the same codes. she's my team member we both are facing the same prob and sorry about the duplicated threat. there's something wrng with my com and i didnt realise that it was posted twice...sorry
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 3 Jul, 2008 - 12:16 AM
Post #4


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 5,388



Thanked 35 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


QUOTE(Ladydice @ 3 Jul, 2008 - 03:13 AM) *

you are right there is someone who posted the same codes.

No worries.

The fact still remains. The reason for the error is you commented out the line that performs the error checking to assure that you are feeding mysql a value. That's the reason for the error is you are allowing a null value to get into the mysql statement & therefor mysql issues a statement with no value, so it throws back an error.

Verify the data, perform the lookup.
User is offlineProfile CardPM

Go to the top of the page

Ladydice
post 3 Jul, 2008 - 12:18 AM
Post #5


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 18


My Contributions


QUOTE(no2pencil @ 3 Jul, 2008 - 12:16 AM) *

QUOTE(Ladydice @ 3 Jul, 2008 - 03:13 AM) *

you are right there is someone who posted the same codes.

No worries.

The fact still remains. The reason for the error is you commented out the line that performs the error checking to assure that you are feeding mysql a value. That's the reason for the error is you are allowing a null value to get into the mysql statement & therefor mysql issues a statement with no value, so it throws back an error.

Verify the data, perform the lookup.


thanks for you help...you were right...thnks again
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/6/08 11:17AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month