Connecting Tech Pros Worldwide Forums | Help | Site Map

mysql_num_rows() argument is not being recognized, any help would be appreciated

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: Oct 20 '09
Hi everyone,

I've recently begun learning PHP and it looks like I took on too much so soon.

I'm attempting to fix a php script that detects whether or not a person is Eligible to join a tournament or not when they register and attempt to join. I'm doing it locally at the moment so i don't need to upload every 5 minutes. Any assistance would be appreciated.

On register.php, I am receiving the following error:

Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/vehement/public_html/ladder/join.php on line 935

Here is the code for joining the tournament:

Expand|Select|Wrap|Line Numbers
  1. function check_if_ladder_under_usergroup($ladderid, $teamid=NULL, $userid=NULL){
  2. global $config;
  3.  
  4. $sql = mysql_query("SELECT * FROM groupstable WHERE `ladderon` = ".$ladderid);
  5. if(mysql_num_rows($sql) > 0){
  6.     //ladder is restricted
  7.     if(empty($teamid) && empty($userid)) return false; //return that is ladder is restricted
  8.  
  9.     $ginfo = mysql_fetch_assoc($sql);
  10.     if(mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND `memberid`=".intval($userid)."")) > 0){
  11.         return true;
  12.     }elseif(empty($teamid)){
  13.         return false;
  14.     }else{
  15.         return (mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND `teamid`=".intval($teamid)."")) > 0);
  16.     }
  17. }
  18. return true; //no restirction
  19. }

On the "if(mysql_num_rows($sql) > 0)" part, I don't understand why it's not a valid argument. Thanks for any advise you can provide!

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,670
#2: Oct 20 '09

re: mysql_num_rows() argument is not being recognized, any help would be appreciated


and once again the standard error …

mysql_query() returns false if something’s gone wrong, and false is not a valid resource.

standard check:
Expand|Select|Wrap|Line Numbers
  1. $resource = mysql_query($sql) or die(mysql_error());
Newbie
 
Join Date: Oct 2009
Posts: 3
#3: Oct 20 '09

re: mysql_num_rows() argument is not being recognized, any help would be appreciated


hi Dormilich,

thank you for the help. it looks like the error is still there even with the new code...
line 935 is:

Expand|Select|Wrap|Line Numbers
  1.  if(mysql_num_rows($sql) > 0){ 
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,670
#4: Oct 20 '09

re: mysql_num_rows() argument is not being recognized, any help would be appreciated


what does
Expand|Select|Wrap|Line Numbers
  1. var_dump($sql);
just before the mysql_num_rows() output?
Newbie
 
Join Date: Oct 2009
Posts: 3
#5: Oct 20 '09

re: mysql_num_rows() argument is not being recognized, any help would be appreciated


hi again,

after spending a lot of time on this with my friend, it seems that $ladderid is returning no value. from the code, it seems it is not adding on ?ladder=1 at the end of the url for the sql database to grab. the website works though, without the restriction so my friend put in a bypass to not see the error but will display the rest of the page.

for reference to anyone else who has such an issue, here is the new code for the section:

Expand|Select|Wrap|Line Numbers
  1. function check_if_ladder_under_usergroup($tournamentid, $teamid=NULL, $userid=NULL){
  2. global $config;
  3.  
  4. $sql = mysql_query("SELECT * FROM groupstable WHERE `ladderon` = ".$ladderid);
  5.  
  6. if($sql !=false)
  7. {
  8.  
  9. if(mysql_num_rows($sql) > 0){
  10. //ladder is restricted
  11.  
  12. if(empty($teamid) && empty($userid)) return false; //return that is ladder is restricted
  13. $ginfo = mysql_fetch_assoc($sql);
  14. if(mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND 
  15.  
  16. `memberid`=".intval($userid)."")) > 0){
  17. return true;
  18. }elseif(empty($teamid)){
  19. return false;
  20. }else{return (mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND 
  21.  
  22. `teamid`=".intval($teamid)."")) > 0);
  23. }
  24. }
  25. }
  26. return true; //no restirction
  27. }
  28.  
thanks for all the help!
Reply