PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tristanlee85
Forum Contributor
Posts: 172 Joined: Fri Dec 19, 2003 7:28 am
Post
by tristanlee85 » Tue Apr 11, 2006 11:20 pm
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?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Tue Apr 11, 2006 11:50 pm
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/>';
}
(#10850)
tristanlee85
Forum Contributor
Posts: 172 Joined: Fri Dec 19, 2003 7:28 am
Post
by tristanlee85 » Wed Apr 12, 2006 12:44 am
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.