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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • macdalor
    New Member
    • Jan 2010
    • 27

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

    Hi! I'm completely new to all dev and trying to put a website together using MySQLI and PHP; was running fine until I try to gather the DB content with the following script:

    Code:
    <?
    $username="xxxxxx";
    $password="xxxxxx";
    $database="maxalien_davidloran";
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM contacts";
    
    $result=mysql_query($query);
    
    $num=mysql_num_rows($result);
    
    
    mysql_close();
    
    echo "<b><center>Database Output</center></b><br><br>";
    
    $i=0;
    while ($i < $num) {
    
    $username=mysql_result($result,$i,"username");
    $password=mysql_result($result,$i,"password");
    $email=mysql_result($result,$i,"email");
    
    echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";
    
    $i++;
    }
    
    ?>
    getting the following error mesg when running it:

    Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/maxalien/public_html/davidloran/test/userCake/dbresult.php on line 12
    Database Output

    Let me know if you need more info and thx for your help
  • macdalor
    New Member
    • Jan 2010
    • 27

    #2
    is anyone able to help please?

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      Something is failing here
      Code:
      mysql_connect(localhost,$username,$password); 
      @mysql_select_db($database) or die( "Unable to select database"); 
      $query="SELECT * FROM contacts"; 
        
      $result=mysql_query($query); 
        
      $num=mysql_num_rows($result);
      You can help yourself by removing the error supression '@' and
      testing the returns using if() and mysql_error().

      Also, further down you are closing the database connection then continuing to use it

      Comment

      Working...