Im卡住了,一直試圖找出現在2個小時。我已經找到了foreach循環,但不知道如何現在插入數據。使用foreach數組插入多行到mysql使用foreach數組
這裏是我的PHP,我做錯了什麼?
$query = "INSERT INTO images (thumb_path, image_path, main_image, project_id) VALUES ";
foreach($_POST as $key => $value) {
$query .= "$thumb_path,$image_path,$main_image,$_POST[project_id])";
$result = mysql_query($query, $connection);
}
謝謝!
我是否應該這樣佈置,對不起,仍然是一個新手,以及它是如何工作的。
foreach($_POST as $key => $value) {
$query = "INSERT INTO images VALUES (thumb_path, image_path, main_image, project_id),";
$query .= "$value[thumb_path], $value[$image_path], $value[$main_image], '$_POST[project_id'])";
}
$result = mysql_query($query, $connection);
這是應該如何設置? ($ _ POST作爲$ key => $ value){ $ query =「INSERT INTO $ query。=「$ value [thumb_path],$ value [$ image_path],$ value [$ main_image],'$ _POST [project_id'])」; } $ result = mysql_query($ query,$ connection); – jrutter 2009-11-29 22:34:31