我正在学习MySQL / PHP,我只是想熟悉它,但我收到了这个错误:
“表'Daniel.food'不存在”
当我运行此代码时......
<?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";
?>
我期待看到任何回复。
答案 0 :(得分:0)
首先,你的创建声明:
mysql_query(“CREATE TABLE food(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),Meal VARCHAR(15),Position VARCHAR(8))或die(mysql_error()”);
包含您的错误检查的查询报价。尝试在'Position VARCHAR(8)'之后关闭你的引用而不是'die(mysql_error()'。