我有一個配方表和配料表,兩個表的主鍵都是自動增量,配方的主鍵是配料中的外鍵。我將數據從html發佈到php。請注意,我的成分文本框是動態生成的,併成功將數據發佈到php腳本。發佈的數據是正確的,當我插入這個數據表我的查詢工作正常,但數據不會添加到MySQL表。我的代碼和輸出是插入查詢不會插入數據到mysql數據庫表
$sql = "insert into recipe (rec_id, Name, Overview,category, Time, Image) values ('', '$name','$overview','$category','$time','$TARGET_PATH')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
$rec_id = mysql_insert_id();
和成分
$ingredient = $_POST['ingredient'];
$amount = $_POST['amount'];
$integer = 0;
while (count($ingredient)>$integer) {
if (($ingredient[$integer] <> "") && ($amount[$integer] <> "")){
$sql = "INSERT INTO `cafe`.`ingredients` (`ingredient_id`, `ingredient_name`, `ammount`, `rec_id`,)
VALUES ('', '".$ingredient[$integer]."', '".$amount[$integer]."', '$rec_id')";
mysql_query($sql);
echo $sql."
";
}
else{
echo "ingredient number ".($integer+1)." is missing values and cannot be inserted.";
}
$integer = ($integer + 1);
}
當我附和了把查詢是
nsert into recipe (rec_id, Name, Overview,category, Time, Image) values ('', 'demo recipe','no overview','meal','10/12/10 : 13:02:33','http://www.localhost/cafe/pics/demo.gif')
INSERT INTO cafe
.ingredients
(ingredient_id
, ingredient_name
, ammount
, rec_id
,) VALUES ('', 'ingredient one', '3gm', '29')
INSERT INTO cafe
.ingredients
(ingredient_id
, ingredient_name
, ammount
, rec_id
,) VALUES ('', 'ingredient two', '3gm', '29')
INSERT INTO cafe
.ingredients
(ingredient_id
, ingredient_name
, ammount
, rec_id
,) VALUES ('', 'ingredient three', '3gm', '29')
,但是當我從成分看mysql表或retriew數據有成分中沒有數據。
刪除
cafe
你可以請張貼的配方和成分的定義表? – 2010-12-10 08:24:50`amount`拼寫`amount` – 2010-12-10 08:46:58