Help with my Script

I apologise in advance for this one it is probably very simple. Whenever I run the following script I get this error, I have looked at everyhting but cannot see the problem:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/daniels/public_html/display.php on line 5

Here is the code:

[php]<?php
include(“connect.php”);
$query=“SELECT * FROM daniels_addresses”;
$result= mysql_query($query);
$num=mysql_numrows($result);
?>

<?PHP $i=0; while ($i<$num) { $FirstName =mysql_result($result,$i,"firstname"); $LastName =mysql_result($result,$i,"lastname"); $Email= mysql_result($result,$i,"email"); ?> <?PHP ++$i; }

?>[/php]
MOD EDIT: Replaced COLOR tags with more appropriate PHP bb code tags

First Name Surname E-Mail
<? echo "$firstname"; ?> <? echo "$lastname"; ?> <? echo "$Email"; ?>

First of all it should by mysql_num_rows($result) and not mysql_numrows($result).
That aside though, the error indicates that $result is not a valid resource ID. There could be a problem with your query. I suggest the following:

[php]

<?php include("connect.php"); $query="SELECT * FROM daniels_addresses"; $result= mysql_query($query) or DIE(' Failed ' . mysql_error() ); $num=mysql_numrows($result); ?> [/php]

That way you can see what specifically the MYSQL error is.

The problem will lie in your query like peg110 mentioned.

$query=“SELECT * FROM daniels_addresses”;

Check to make sure that the daniels_addresses table actually exists.

As Paul stated it is probably an error in the query…Not always that the table doesn’t exists, It could be numerous problems.

If you can’t figure out the error it is giving you post it here and we can help you out.

I had botched tha table creation. I recreated the table and now it is fine. Thanks for your help.

Sponsor our Newsletter | Privacy Policy | Terms of Service