Jonathan Harvey Posted September 6, 2009 Report Share Posted September 6, 2009 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 More sharing options...
dsonesuk Posted September 6, 2009 Report Share Posted September 6, 2009 (edited) try this:mysql_query("CREATE TABLE dishes (dish_id int NOT NULL PRIMARY KEY AUTO_INCREMENT, dishname varchar(255), price decimal(4,2), is_spicy int)");mysql_query("INSERT INTO dishes VALUES (2,'Cashew Nuts and White Mushrooms',4.95,0)"); //missing bracket Edited September 6, 2009 by dsonesuk Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now