开发者

PHP / MySQL: Simple question regarding table creation

I'm learning MySQL / PHP and I'm just trying to get familiar with it but I'm getting this error:

"Table 'Daniel.food' doesn't exist"

when I run this c开发者_开发问答ode...

<?php

mysql_connect("localhost", "USER", "PASSWORD") or die(mysql_error());

mysql_query("CREATE DATABASE Daniel") or die(mysql_error());

echo "Database created<br/><br/>";

mysql_select_db("Daniel") or die(mysql_error());

mysql_query("CREATE TABLE food(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
Meal VARCHAR(15),
Position VARCHAR(8)) or die(mysql_error()");

echo "Table: \"food\" created successfully<br/><br/>";

mysql_query("CREATE TABLE family(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
Position VARCHAR(15),
Age INT) or die(mysql_error()");

echo "Table: \"family\" created successfully<br/><br/>";

mysql_query("INSERT INTO food
(Meal, Position) VALUES ('Steak', 'Dad')") or die(mysql_error());

mysql_query("INSERT INTO food
(Meal, Position) VALUES ('Salad', 'Mom')") or die(mysql_error());

mysql_query("INSERT INTO food
(Meal, Position) VALUES ('Spinach Soup', '')") or die(mysql_error());

mysql_query("INSERT INTO food
(Meal, Position) VALUES ('Tacos', 'Dad')") or die(mysql_error());

mysql_query("INSERT INTO family
(Position, Age) VALUES ('Dad', '41')") or die(mysql_error());

mysql_query("INSERT INTO family
(Position, Age) VALUES ('Mom', '45')") or die(mysql_error());

mysql_query("INSERT INTO family
(Position, Age) VALUES ('Daughter', '17')") or die(mysql_error());

mysql_query("INSERT INTO family
(Position, Age) VALUES ('Dog', '')") or die(mysql_error());

echo "Values entered succussfully";

?>

I look forward to seeing any responses.


For one, your create statement:

mysql_query("CREATE TABLE food( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), Meal VARCHAR(15), Position VARCHAR(8)) or die(mysql_error()");

has the query quote encompassing your error check. Try closing your quote after the 'Position VARCHAR(8))' instead of the 'die(mysql_error()'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜