Nucleus Posted February 4, 2010 Share Posted February 4, 2010 This code <? include("dbinfo.inc.php"); 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_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>">E-mail</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> </tr> <? ++$i; } echo "</table>"; ?> Gives me this error [04-Feb-2010 09:24:41] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home1/koutouro/public_html/ioannou/example/index.php on line 8 [04-Feb-2010 09:24:57] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home1/koutouro/public_html/ioannou/example/index.php on line 8 [04-Feb-2010 09:25:09] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home1/koutouro/public_html/ioannou/example/index.php on line 8 What I'm I doing wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/190897-php-warning-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
PravinS Posted February 4, 2010 Share Posted February 4, 2010 Its $num=mysql_num_rows($result); not $num=mysql_numrows($result); Quote Link to comment https://forums.phpfreaks.com/topic/190897-php-warning-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1006667 Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2010 Share Posted February 4, 2010 mysql_numrows() is a perfectly valid (but depreciated) alias name for the mysql_num_rows() function and is not the reason why you are getting an error about an invalid result resource. The error is because your query failed to execute due to an error and returned a FALSE value instead of a result resource. For debugging, echo mysql_error() on the line right after the mysql_query() statement to find out why it failed. Quote Link to comment https://forums.phpfreaks.com/topic/190897-php-warning-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1006718 Share on other sites More sharing options...
Nucleus Posted February 4, 2010 Author Share Posted February 4, 2010 Forgive my ignorance, but do you mean something like this? $result=mysql_query($query); echo mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/190897-php-warning-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1006759 Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2010 Share Posted February 4, 2010 That would be on the same line, not the line right after... That would however work assuming there is a semi-colon ; on the end of it to terminate the statement. Quote Link to comment https://forums.phpfreaks.com/topic/190897-php-warning-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1006763 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.