Forum Moderators: coopster

Message Too Old, No Replies

MySQL PHP numrows

         

tahu forever

12:46 am on Apr 21, 2003 (gmt 0)

10+ Year Member



I get this error when trying to execute this code - can anyone see where the problem is?

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/bloomers/public_html/count.php on line 17


<?

$dbhost = "localhost";
$dbuser = "bloomers";
$dbpass = "*****";
$dbname = "bloomers_portal";
$table = "messages";
$no = "no";

mysql_connect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to database");
@mysql_select_db("$dbname") or die ("Unable to retrieve news from database");
$sqlquery = "SELECT * FROM messages WHERE read ='$no' AND recipient = '$customerid'";
$result = mysql_query($sqlquery);
$number = mysql_numrows($result);

$i = 0;

if ($number <1)
{
echo "<center><a href=inbox.php>You have no messages in your inbox.</font></center>";
}

else {
while ($number > $i)
{
echo " <a href=inbox.php>You have $number new messages.</font>";

$i++;
}
}

?>

mavherick

12:51 am on Apr 21, 2003 (gmt 0)

10+ Year Member



That's because your query throws an error. So this line

$result = mysql_query($sqlquery);

isn't executing correctly meaning that there's a problem with your query somewhere.

Just a wild guess here, but is recipient an integer of some sort? then it shouldn't be enclosed in single quotes.

mavherick

tahu forever

1:00 am on Apr 21, 2003 (gmt 0)

10+ Year Member



recipient is a word eg JohnSmith (varchar)

shady

1:09 am on Apr 21, 2003 (gmt 0)

10+ Year Member



"read" is a reserved word. Change the column to messages_read for example and it should work

tahu forever

1:19 am on Apr 21, 2003 (gmt 0)

10+ Year Member



Cool - thanks shady. Forgot about reserved words :¦