Page 1 of 1

Warning: mysql_numrows()

Posted: Tue Apr 11, 2006 11:20 pm
by tristanlee85

Code: Select all

<?
$username="user";
$password="pass";
$database="fedex";

$first=$_POST['first'];
$last=$_POST['last'];
$manager=$_POST['manager'];
$comment=$_POST['comment'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO eval_num VALUES ('','$first','$last','$manager','$comment')";
mysql_query($query);

mysql_close();
?>

<html><body>
<form action="index.php" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Manager: <input type="text" name="manager"><br>
Comment: <input type="text" name="comment"><br>
<input type="Submit">
</form></body></html>

<?
$query="SELECT * FROM eval_num";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$manager=mysql_result($result,$i,"manager");
$comment=mysql_result($result,$i,"comment");

echo "<b>$first $last</b><br>Manager: $manager<br>Comment: $comment<br>";

$i++;
}
?>
I keep getting the error:

Code: Select all

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /opt/lampp/htdocs/fedex/index.php on line 35
I'm not sure what's going on here. Is it because there are no values in the table?

Posted: Tue Apr 11, 2006 11:50 pm
by Christopher
You should add something like the following after you queries to see what is going on:

Code: Select all

if (mysql_errno() != 0) {
     echo 'Error: ' . mysql_error() . '<br/>';
}

Posted: Wed Apr 12, 2006 12:44 am
by tristanlee85
Thanks. It was looking for a database to connect to so I just added (2) of these to the PHP part of the script:

Code: Select all

<?
$username="user";
$password="pass";
$database="fedex";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
Now I just need to figure out now to not submit fields if one or more are empty I'll have it made.