想请教我在ajax传值进php
在使用foreach insert进sql 却进不了sql
我有测试过不使用foreach 直接在php下 sql 是可行的 代表ajax有成功传值过去php里
但我在使用foreach时 就会失败
所以我在想是不是我在ajax与foreach上哪边少做了什么动作了?
请求帮忙 以下是code
<script>
var summaryData = $("#addcontent").jqxGrid('getcolumnaggregateddata',
'total', ['sum']);
var totalamount = "&total_deductions=" + summaryData.sum;
var rows = $('#addcontent').jqxGrid('getrows');
var result = "";
for(var i = 0; i < rows.length; i++)
{
var row = rows[i];
result += "&name=" + row.id + "&quantity=" + row.quantity +
"&purchase_price=" + row.price + "&total=" + row.total + "\n";
}
$.ajax({
url:"edit.php",
data: 'id='+select.id + '&total_balance='+select.total_amount +
totalamount + result,
type: "POST",
success: function(msg){
alert("成功");
},
error:function(xhr, ajaxOptions, thrownError){
alert("错误");
}
});
</script>
<?php
require_once("dbtools.inc.php");
//入商品
$product_id = $_POST['name'];
$quantity = $_POST['quantity'];
$purchase_price = $_POST['purchase_price'];
$total= $_POST['total'];
//建立资料连接
$link = create_connection();
//释放 $result 占用的内存
mysql_free_result($result);
//执行 SQL 命令,新增此帐号
foreach($product_id as $v){
$sql = "INSERT INTO pre_item ( product_id ) VALUES ( '$v' )";
$result = execute_sql("pos", $sql, $link);
}
//关闭资料连接
mysql_close($link);
?>