mysql_fetch_array(): supplied argument is not a valid MySQL result ...

Discussion in 'MySQL' started by lokielookies, Apr 8, 2007.

  1. #1
    Installation of a script brings up this message:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mypathto/read.php on line 60

    Can somebody tells me what it means?
    I know others have been able to install the script without any problem.

    Greetz!
    Mieke
     
    lokielookies, Apr 8, 2007 IP
  2. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #2
    I *think* this error occurs when the result returned in the previous mysql_query was invalid. Try checking the SQL query you made just before the above line. :eek:
     
    Darkhodge, Apr 8, 2007 IP
  3. kashem

    kashem Banned

    Messages:
    1,250
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Post some code here
     
    kashem, Apr 8, 2007 IP
  4. ramfir

    ramfir Active Member

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    what script are you installing?
     
    ramfir, Apr 8, 2007 IP
  5. ideas_man

    ideas_man Active Member

    Messages:
    212
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Like Darkhodge said, this can occur when you try to use a result set function on something which is not a valid mysql result set.

    It might be that your script is not connecting to the database correctly and so cannot get results... or that your query has errors in it.

    Try using mysql_error() to highlight where the problem might be.Writing the following should help you deduce whether your sql query is valid. Add it just after the mysql_query() in question:

    echo mysql_error();
    PHP:
    I find the above snippet very useful and has saved me many times from simple typo errors in my sql syntax.

    I hope it helps :)
     
    ideas_man, Apr 8, 2007 IP
  6. lokielookies

    lokielookies Well-Known Member

    Messages:
    1,246
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #6
    This is the code in the read.php file:


    <body>
    <table width="587" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="3"><img src="images/read/top.gif" width="590" height="138"></td>
      </tr>
      <tr>
        <td width="35" bgcolor="#FFFFFF"><img src="images/read/side.gif"></td>
        <td width="520" valign="top" bgcolor="#FFFFFF"><p>
          <p>      
          <div class='contentboxgen'>
    <TABLE width="90%" align="center"><?
         mysql_connect("localhost", "db_user", "password");
         mysql_select_db("db_name");
         $query = "SELECT name, email, url, testimonial, time FROM testimonials ORDER BY time DESC";
         $resultaat = mysql_query($query);
         $rij = mysql_fetch_array($resultaat);
         while ($rij) {
              $datum = date("d F Y - H:i:s", $rij["time"]);
              ?>
    <TBODY>
    <TR>
    <TD width="20%" valign="top">Name:</TD>
    <TD width="80%"><?print $rij["name"];?></TD></TR>
    <TR>
      <TD valign="top">Email:</TD>
      <TD><?print $rij["email"];?></TD>
    </TR>
    <TR>
    <TD width="20%" valign="top">URL:</TD>
    <TD width="80%"><?print $rij["url"];?></TD></TR>
    <TR>
    <TD width="20%" valign="top">Testimonial:</TD>
    <TD width="80%"><?print $rij["testimonial"];?></TD></TR>
    <TR>
    <TD width="20%" valign="top">Date:</TD>
    <TD width="80%"><?print $datum;?></TD></TR>
    <TR>
    <TD>&nbsp;</TD>
    <TD>&nbsp;</TD></TR>
    <TR>
    <TD width="20%">
    <HR SIZE=1>
    </TD>
    <TD width="80%">
    <HR SIZE=1>
    </TD></TR>
    <TR>
    <TD>&nbsp;</TD>
    <TD>&nbsp;</TD></TR><?
              $rij = mysql_fetch_array($resultaat);
         }
         mysql_close();
         ?></TBODY></TABLE>
    </div></td>
        <td width="35" bgcolor="#FFFFFF"><img src="images/read/side.gif"></td>
      </tr>
      <tr>
        <td colspan="3"><img src="images/read/bottom.gif" width="590" height="55"></td>
      </tr>
    </table><p align="center"><br>
      <span class="style1">Powered by <a href="http://www.getthattestimonial.com" target="_blank">Get That Testimonial </a></span>
    </body>
    
    PHP:
     
    lokielookies, Apr 10, 2007 IP
  7. JochenVandeVelde

    JochenVandeVelde Peon

    Messages:
    412
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The MySQL query probably didn't return any results, you can check for this like this:

    
    <?php
    
    $result = mysql_query("your query here");
    
    if(mysql_num_rows($result) > 0)
    {
    // query successful, result returned, put your processing or output script here
    }
    else
    {
    // no result returned, no data matched your query, print an error
    }
    ?>
    
    Code (markup):
    Try that, if it works please give me some green rep :p

    or you could just tell PHP not to output these warnings:

    
    <?php
    // put this at the top of every file (or only in your config file)
    error_reporting(E_ALL^E_NOTICE^E_WARNING);
    
    ?>
    
    Code (markup):
     
    JochenVandeVelde, Apr 10, 2007 IP
  8. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #8
    You could also help us by showing us the table structure of "testimonials" :)
     
    Darkhodge, Apr 10, 2007 IP
  9. lokielookies

    lokielookies Well-Known Member

    Messages:
    1,246
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #9
    This is the info in the db.sql file:



    CREATE TABLE `testimonials` (
      `name` varchar(50) NOT NULL default '',
      `email` varchar(250) NOT NULL default '',
      `url` text NOT NULL,
      `testimonial` text NOT NULL,
      `time` int(10) NOT NULL default '0',
      PRIMARY KEY  (`name`,`time`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    HTML:
     
    lokielookies, Apr 10, 2007 IP
  10. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #10
    Here you go! :)

    I changed the code a little but it should work fine - just replace the contents of your read.php file with this code (first back the file up though). If it doesn't work please tell me the error message you get as it's probably just a careless mistake.

    If it works please give me a green rep :D

    
    <?
    mysql_connect("localhost", "db_user", "password");
    mysql_select_db("db_name");
    $query = "SELECT * FROM testimonials ORDER BY time DESC";
    $resultaat = mysql_query($query);
    
      while ($rij = mysql_fetch_array($resultaat)) {
       
       $name        = $rij['name'];
       $email       = $rij['email'];
       $url  	    = $rij['url'];
       $testimonial = $rij['testimonial'];
       $datum       = date("d F Y - H:i:s", $rij['time']);
       
       print <<<HERE
    
    <body>
    <table width="587" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="3"><img src="images/read/top.gif" width="590" height="138"></td>
      </tr>
      <tr>
        <td width="35" bgcolor="#FFFFFF"><img src="images/read/side.gif"></td>
        <td width="520" valign="top" bgcolor="#FFFFFF"><p>
          <p>      
          <div class='contentboxgen'>
    <TABLE width="90%" align="center">
    <TBODY>
    <TR>
    <TD width="20%" valign="top">Name:</TD>
    <TD width="80%">$name</TD></TR>
    <TR>
      <TD valign="top">Email:</TD>
      <TD>$email</TD>
    </TR>
    <TR>
    <TD width="20%" valign="top">URL:</TD>
    <TD width="80%">$url</TD></TR>
    <TR>
    <TD width="20%" valign="top">Testimonial:</TD>
    <TD width="80%">$testimonial</TD></TR>
    <TR>
    <TD width="20%" valign="top">Date:</TD>
    <TD width="80%">$datum</TD></TR>
    <TR>
    <TD>&nbsp;</TD>
    <TD>&nbsp;</TD></TR>
    <TR>
    <TD width="20%">
    <HR SIZE=1>
    </TD>
    <TD width="80%">
    <HR SIZE=1>
    </TD></TR>
    <TR>
    <TD>&nbsp;</TD>
    <TD>&nbsp;</TD></TR>
    HERE;
    }
    
    print <<<HERE
    </TBODY></TABLE>
    </div></td>
        <td width="35" bgcolor="#FFFFFF"><img src="images/read/side.gif"></td>
      </tr>
      <tr>
        <td colspan="3"><img src="images/read/bottom.gif" width="590" height="55"></td>
      </tr>
    </table><p align="center"><br>
      <span class="style1">Powered by <a href="http://www.getthattestimonial.com" target="_blank">Get That Testimonial </a></span>
    </body>
    HERE;
    
    ?>
    
    Code (markup):
     
    Darkhodge, Apr 10, 2007 IP
  11. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #11
    So did you solve this problem or what?
     
    Darkhodge, Apr 11, 2007 IP
  12. lokielookies

    lokielookies Well-Known Member

    Messages:
    1,246
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    150
    #12
    Sorry for my late reply

    I've uploaded the new read.php. This is what appears:

    Invalid query: Table 'testimonials.testimonials' doesn't exist
     
    lokielookies, Apr 18, 2007 IP
  13. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #13
    Are you sure you've installed the MySQL database properly? Have you manually gone into the database and checked that the table exists?

    Also why does that say "testimonials.testimonials" instead of just "testimonials"? :confused:
     
    Darkhodge, Apr 18, 2007 IP
  14. webster13045

    webster13045 Peon

    Messages:
    878
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #14
    some files need to be chmod to 0666 or 0777
     
    webster13045, Apr 18, 2007 IP