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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seigaku
    New Member
    • Oct 2009
    • 3

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

    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:

    Code:
    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:

    Code:
    function check_if_ladder_under_usergroup($ladderid, $teamid=NULL, $userid=NULL){
    global $config;
    
    $sql = mysql_query("SELECT * FROM groupstable WHERE `ladderon` = ".$ladderid);
    if(mysql_num_rows($sql) > 0){
    	//ladder is restricted
    	if(empty($teamid) && empty($userid)) return false; //return that is ladder is restricted
    	
    	$ginfo = mysql_fetch_assoc($sql);
    	if(mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND `memberid`=".intval($userid)."")) > 0){
    		return true;
    	}elseif(empty($teamid)){
    		return false;
    	}else{
    		return (mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND `teamid`=".intval($teamid)."")) > 0);
    	}
    }
    return true; //no restirction
    }

    On the "if(mysql_num_r ows($sql) > 0)" part, I don't understand why it's not a valid argument. Thanks for any advise you can provide!
    Last edited by Dormilich; Oct 20 '09, 07:27 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    and once again the standard error …

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

    standard check:
    Code:
    $resource = mysql_query($sql) or die(mysql_error());

    Comment

    • seigaku
      New Member
      • Oct 2009
      • 3

      #3
      hi Dormilich,

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

      Code:
       if(mysql_num_rows($sql) > 0){

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        what does
        Code:
        var_dump($sql);
        just before the mysql_num_rows( ) output?

        Comment

        • seigaku
          New Member
          • Oct 2009
          • 3

          #5
          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:

          Code:
          function check_if_ladder_under_usergroup($tournamentid, $teamid=NULL, $userid=NULL){
          global $config;
          
          $sql = mysql_query("SELECT * FROM groupstable WHERE `ladderon` = ".$ladderid);
          
          if($sql !=false)
          {
          
          if(mysql_num_rows($sql) > 0){
          //ladder is restricted
          
          if(empty($teamid) && empty($userid)) return false; //return that is ladder is restricted
          $ginfo = mysql_fetch_assoc($sql);
          if(mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND 
          
          `memberid`=".intval($userid)."")) > 0){
          return true;
          }elseif(empty($teamid)){
          return false;
          }else{return (mysql_num_rows(mysql_query("SELECT * FROM groupsmembers WHERE `groupid` = ".$ginfo['id']." AND 
          
          `teamid`=".intval($teamid)."")) > 0);
          }
          }
          }
          return true; //no restirction
          }
          thanks for all the help!

          Comment

          Working...