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

Reply

Join Date: May 2007
Posts: 1
Reputation: SuperioAssassin is an unknown quantity at this point 
Solved Threads: 0
SuperioAssassin SuperioAssassin is offline Offline
Newbie Poster

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

 
0
  #1
May 7th, 2007
I have been looking at this code for some time and just can not figure anything wron with it.

My Error Message is: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hsphere/local/home/gwthorn/htpsinc-web.com/York_County/login.php on line 13

I commeted 13

  1. <?php
  2. session_start();
  3.  
  4. //The fields are censored but the database does connect.
  5.  
  6. mysql_connect("-censored-","-censored-","-censored");
  7. mysql_select_db("-censored-");
  8.  
  9. if(isset($_POST['login'])) {
  10. $username = htmlspecialchars($_POST['username'], ENT_QUOTES);
  11. $password = htmlspecialchars($_POST['password'], ENT_QUOTES);
  12. $password = md5($password);
  13. $sql = mysql_query("SELECT * FROM user_system WHERE username='$username' AND password='$password'");
  14.  
  15. if(mysql_num_rows($sql)>0) { //!!!!!!!!!!!!!!!!!!!!!!!!Line 13
  16. $_SESSION['auth'] = true;
  17. setcookie("avxsystem_user",$username,time()+30*30*30*30*365);
  18. setcookie("avxsystem_pass",$password,time()+30*30*30*30*365);
  19. echo "<p>Login Successful</p>";
  20. }
  21.  
  22. else {
  23. echo "<p>Sorry, you are unable to login because you have got your username/password combination wrong. Please check spelling & try again.";
  24. }
  25. }
  26. else {
  27. echo $message;
  28. }
  29. ?>
Last edited by stymiee; May 7th, 2007 at 11:00 am. Reason: used php [code]
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

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

 
0
  #2
May 7th, 2007
That means your query failed. Echo it out and look for an error or use mysql_error() to see what the error is.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 7
Reputation: omick16 is an unknown quantity at this point 
Solved Threads: 0
omick16's Avatar
omick16 omick16 is offline Offline
Newbie Poster

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

 
0
  #3
May 8th, 2007
i'm not so sure though, but i guess, there's something wrong in your query... with regards to the proper usage of single quotation marks... single quotation marks will be taken literally so for example '$username' is the same as $username (literally) while "$username" will be taken by it's value so for example if $username=50; echo "$username"; ---> the output is 50.

hmmm... i'm not so sure bout this though... i'm still a student...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 68
Reputation: johny_d is an unknown quantity at this point 
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

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

 
0
  #4
May 8th, 2007
The quotes are ok.
I think your problem comes from that
  1. htmlspecialchars
piece of code, because if you give an echo to
htmlspecialchars($_POST['username'], ENT_QUOTES);
before entering it in the mysql query you will probably see your username string contains at least one # charcater (the password is hashed anyway so doesn't have this problem).

Anyway, if your username string contains a # character, in mysql everything after that char is considered a comment so your sql statement is broken in that point and that's why you get this error.

I suggest you test it first with some simple, clean strings (user: abcd, pass: xyzw) and without
htmlspecialchars
and see if it works and after that go to more complicated stuff.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

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

 
0
  #5
May 8th, 2007
johy_d is right. Your problem could well lie within the htmlspecialchars() function.

Only way to identify this is.
Instead of putting the query directly into mysql_query().

Do.
  1. $query = "SELECT * FROM table";
  2. /* This will output your query then exit the script */.
  3. echo $query; exit;
  4. /* run query with mysql error functionallity */
  5. $ret = mysql_query($query) or die(mysql_error());

NOTE: After observing your query, you'll need to remote the exit; or the "echo $query; exit;" So that execution can continue onto the mysql_query() function.

Identify what is working first, before trying to figure out what isnt working.

Any questions just ask.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC