accessing information from a db
Hi,
I'm new w/ php/mysql... I trying to display information from a db.... Here is the code in question.. Below that is how I created the db, it went through ok, then the error I get when I try it out... Any help would be great.
<html>
<body>
<?
$db = mysql_connect("localhost", "mysql");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
printf("First Name: %s<br>\n", mysql_result($result,0,"first"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));
printf("Address: %s<br>\n", mysql_result($result,0,"address"));
printf("Position: %s<br>\n", mysql_result($result,0,"position"));
?>
</body>
</html>
CREATE TABLE employees ( id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, first varchar(20), last varchar(20), address varchar(255), position varchar(50), PRIMARY KEY (id), UNIQUE id (id));INSERT INTO employees VALUES (1,'Bob','Smith','128 Here St, Cityname','Marketing Manager');
INSERT INTO employees VALUES (2,'John','Roberts','45 There St , Townville','Telephonist');
INSERT INTO employees VALUES (3,'Brad','Johnson','1/34 Nowhere Blvd, Snowston','Doorman');
mysql -u mysql mydb < mydb.dump
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/php/db_test.php on line 25
First Name:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/php/db_test.php on line 29
Last Name:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/php/db_test.php on line 33
Address:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/apache/htdocs/php/db_test.php on line 37
Position:
|