Jump to content

Need Help With Simple Problem


Jonathan Harvey

Recommended Posts

Ok I'm new to php and sql. I'm working out of a book and one of the excersises is to create a database, with a table containing dishes in it, then display all the dishes ordered by price, here is my code:

$database = mysql_connect("localhost", "root", "");if(!$database) {	die('sorry but we couldn\'t connect' .mysql_error());}mysql_query("CREATE DATABASE chapter_7");mysql_select_db("chapter_7", $database);mysql_query("CREATE TABLE dishes (dish_id int NOT NULL AUTO_INCREMENT, dishname varchar(255), price decimal(4,2), is_spicy int)");mysql_query("INSERT INTO dishes VALUES (1,'Walnut Bun',1.00,0)");mysql_query("INSERT INTO dishes VALUES (2,'Cashew Nuts and White Mushrooms',4.95,0");mysql_query("INSERT INTO dishes VALUES (3,'Dried Mulberries',3.00,0)");mysql_query("INSERT INTO dishes VALUES (4,'Eggplant with Chili Sauce',6.50,1) ");mysql_query("INSERT INTO dishes VALUES (5,'Red Bean Bun',1.00,0)");mysql_query("INSERT INTO dishes VALUES (6,'General Tso\'s Chicken',5.50,1)");mysql_select_db("chapter_7", $database);$result = mysql_query("SELECT * FROM dishes ORDER BY price");while($row = mysql_fetch_array($result))  {  echo $row['dishname'];  echo " " . $row['price'];  echo " " . $row['is_spicy'];  echo "<br />";  }mysql_close($database);

And here is the error I'm getting: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Learning PHP\mysqlpractice.php on line 44can Anybody tell me what I'm doing wrong? thanks ahead of time!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...