E作者kinglislie (小黑)
看板PHP
標題[請益] 資料庫相關
時間Wed Jun 18 17:15:03 2008
我用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
→ jimms:53行是....? 06/18 17:24
※ 編輯: kinglislie 來自: 123.193.146.62 (06/18 17:27)
推 yanli2:if ((isset($_POST["MM_insert"]))←多一個括號,右邊也是 06/18 17:28
→ kinglislie:不過那是系統自動產生的程式碼說...我檢查一下成功的 06/18 17:31
→ kinglislie:也都是相同的括法耶>_____<.... 06/18 17:32
→ arianda:BOM?還是你這檔案最前面有空白? 06/18 18:02
→ arianda:黃色部份的header使用時候,前面不可輸出任何字元 06/18 18:03
→ arianda:藍色部份你要先確認$_POST['pizza _name']是陣列元素 06/18 18:04
→ arianda:用var_dump($_POST['pizza _name'])看看結構 06/18 18:04