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
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.
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
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> </TD> <TD> </TD></TR> <TR> <TD width="20%"> <HR SIZE=1> </TD> <TD width="80%"> <HR SIZE=1> </TD></TR> <TR> <TD> </TD> <TD> </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:
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 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):
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:
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 <? 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> </TD> <TD> </TD></TR> <TR> <TD width="20%"> <HR SIZE=1> </TD> <TD width="80%"> <HR SIZE=1> </TD></TR> <TR> <TD> </TD> <TD> </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):
Sorry for my late reply I've uploaded the new read.php. This is what appears: Invalid query: Table 'testimonials.testimonials' doesn't exist
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"?