Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

After uploading the site to my web server I get this message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource 
in /home1/m1k3ey/public_html/MikeyDev.com/teamdesire/playersheet.php on line 8

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource 
in /home1/m1k3ey/public_html/MikeyDev.com/teamdesire/playersheet.php on line 9

My PHP version is:

PHP Version 5.2.17

I cant see where im going wrong in my code, can anyone please assist:

          mysql_select_db('teamdesire', $link);
          $query = "SELECT * FROM playershowercase";
          $result = mysql_query($query,$link);
          $row = array();
Line 8 >  while($row[] = mysql_fetch_array($result));
Line 9 >  $count = mysql_num_rows($result);
          $random = rand(0,$count-1);
share|improve this question
PHP version into your server ??? – d.danailov Jul 16 at 15:17
PHP Version 5.2.17 – MikeyT Jul 16 at 15:20
1  
As per the usual for your error message: Your query has failed somehow, your code blindly assumes success, and blundered onwards. – Marc B Jul 16 at 15:22
@MikeyT - have you tried $result = mysql_query($query,$link) or die (mysql_error()); ? Or var_dump($result? – andrewsi Jul 16 at 15:27
Yes ive tried that, in my error log it says exactly the same error which is displayed on screen – MikeyT Jul 16 at 15:29
show 1 more comment

marked as duplicate by Marc B, N.B., andrewsi, PeeHaa, tereško Jul 18 at 6:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

Maybe something like the following?

      mysql_select_db('teamdesire', $link);
      $query = "SELECT * FROM playershowercase";
      $result = mysql_query($query,$link);
      $row = mysql_fetch_assoc($result);
      $count = mysql_num_rows($result);
      $random = rand(0,$count-1);

Or

      mysql_select_db('teamdesire', $link);
      $query = "SELECT * FROM playershowercase";
      $result = mysql_query($query,$link);
      while ($row = mysql_fetch_array($result, MYSQL_NUM))
      $count = mysql_num_rows($result);
      $random = rand(0,$count-1);
share|improve this answer

Possible error sources:

  • Db is not running on specified socket or port.
  • Insufficient permissions on the table or database.
  • Incorrect login credentials.
  • Table does not exist or is misspelled.

Echo line per line when you troubleshoot.

is_resource($link) or die('Could not connect');
mysql_query(...);
echo mysql_error();
share|improve this answer

Try this:

          mysql_select_db('teamdesire', $link);
          $query = "SELECT * FROM playershowercase";
          $result = mysql_query($query,$link);
          $row = array();
          while($result = mysql_fetch_array($result))
          {
          $row[]=$result;
          }
          $count = mysql_num_rows($result);
          $random = rand(0,$count-1);
share|improve this answer
I get the same error again unfortunately – MikeyT Jul 16 at 15:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.