请问,在order_add_do.php才能将此页面的数组,插入到数据库?
在每次单击“添加商品”的时候,都会弹出两个text文本框。在另一个页面上不能确定数组里面有几个值!
<form action="order_add_do.php" method="post">
<a onClick="addTest()"><font style="cursor:hand;" color="#0033CC">添加商品</font></a> <br /><script type="text/javascript">
function addTest(){
document.getElementById("add").innerHTML+="商品货号:<input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数 量:<input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /><br />";
}
</script>
<br />商品货号:<input type="text" name="shop_item[]" style=" width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;" />
数 量:<input type="text" name="shop_count[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>
</form>
在每次单击“添加商品”的时候,都会弹出两个text文本框。在另一个页面上不能确定数组里面有几个值!
<form action="order_add_do.php" method="post">
<a onClick="addTest()"><font style="cursor:hand;" color="#0033CC">添加商品</font></a> <br /><script type="text/javascript">
function addTest(){
document.getElementById("add").innerHTML+="商品货号:<input type=text name=shop_item[] style='width:100px; border-bottom:1p #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;' /> 数 量:<input type=text name=shop_count[] style='width:40px; border-bottom:1px #000000 solid; border-top:none; border-left:none; border_right:none; width:80px;' /><br />";
}
</script>
<br />商品货号:<input type="text" name="shop_item[]" style=" width:100px;border-bottom:1px #000000 solid; border-top:none; border-left:none; border-right:none; width:80px;" />
数 量:<input type="text" name="shop_count[]" style=" border-bottom:1px #000000 solid; border-right:none; border-left:none; border-top:none; width:80px;"/>
</form>
2.der_add_do.php頁面:
if ($_POST['New'])
{
$sql="INSERT INTO user (.....) VALUES(.....)";
$result=mysql_query($sql) or die(mysql_error());
if($result)
{
echo "Add user successs!";
}
else
echo mysql_error().$sql;
}
for ($i=0;$i<$count;$i++)
{....
}$count=count($_POST[shop_count]);
for ($i=0;$i<$count;$i++)
{....
}
比如:
$countArray = serialize($_POST[shop_count]);
直接把 $countArray 插入到数据库中.
取出的时候反序列:如:
$countArray = unserialize($dataInfo['shop_count']);这样就可以
在循環裏寫你的插入語句,還有你這是插入幾條數據呢,是不是一對一的關係呢,一個商品對應一個數量?然後插入一條數據?
那樣
$count=count($_POST[shop_item]);
for ($i=0;$i <$count;$i++)
{
$sql="insert into table (item,qty)values(".$_POST[shop_item][$i].",".$_POST[shop_count]." )";
}你給的條件我只能猜寫到這麼多
商品名|数量
商品名|数量
商品名|数量写入数据库
读出来时先explode("\r\n",$rs);
再每条数据explode("|",$rss);
require_once("../baohan/config.php");
$shop_item=$_POST["shop_item"];
$shop_count=$_POST["shop_count"];
$i=0;
while($i<count($shop_item))
{
$name=$shop_item[$i];
$count=$shop_count[$i];
$i++;$sql="insert into baokelong.order(sp_item,count) values('$name',$count)";
$result=mysql_query($sql);}
?>搞定了。谢谢大家~~~