[請益] 資料庫相關

看板PHP作者時間17年前 (2008/06/18 17:15), 編輯推噓1(107)
留言8則, 4人參與, 最新討論串1/2 (看更多)
我用Dreamweaver插入記錄功能把form裡的資料放入資料庫 有幾個form已經是成功的 不過突然有一個一直遇到以下錯誤 Warning: Invalid argument supplied for foreach() in C:\AppServ\www\XXX.php on line 37 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\XXX.php:37) in C:\AppServ\www\XXX.php on line 53 不知道有沒有哪位大大知道如何解決?? 有點冗長...黃色為第53行 藍色為第37行 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { foreach($_POST['pizza _name'] as $i => $val){ $insertSQL = sprintf("INSERT INTO pizza_order (ordernum, pizza_name, Vegetable, PS, Price) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['ordernum'], "text"), GetSQLValueString($_POST['pizza _name'][$i], "text"), GetSQLValueString($_POST['Vegetable'][$i], "text"), GetSQLValueString($_POST['PS'][$i], "text"), GetSQLValueString($_POST['Price'][$i], "int")); mysql_select_db($database_products, $products); $Result1 = mysql_query($insertSQL, $products) or die(mysql_error()); } $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.146.62

06/18 17:24, , 1F
53行是....?
06/18 17:24, 1F
※ 編輯: kinglislie 來自: 123.193.146.62 (06/18 17:27)

06/18 17:28, , 2F
if ((isset($_POST["MM_insert"]))←多一個括號,右邊也是
06/18 17:28, 2F

06/18 17:31, , 3F
不過那是系統自動產生的程式碼說...我檢查一下成功的
06/18 17:31, 3F

06/18 17:32, , 4F
也都是相同的括法耶>_____<....
06/18 17:32, 4F

06/18 18:02, , 5F
BOM?還是你這檔案最前面有空白?
06/18 18:02, 5F

06/18 18:03, , 6F
黃色部份的header使用時候,前面不可輸出任何字元
06/18 18:03, 6F

06/18 18:04, , 7F
藍色部份你要先確認$_POST['pizza _name']是陣列元素
06/18 18:04, 7F

06/18 18:04, , 8F
用var_dump($_POST['pizza _name'])看看結構
06/18 18:04, 8F
文章代碼(AID): #18MD8Puj (PHP)
討論串 (同標題文章)
文章代碼(AID): #18MD8Puj (PHP)