【发布时间】:2018-09-23 19:40:25
【问题描述】:
我从购物车表中获取数组值,我想将购物车数组值插入到我的订单表中,但我面临的问题只是最后一个数组值只插入到我的数据库中,但我想将所有购物车值插入到我的订单表。
/*This is the form page I was getting cart value*/
<form>
<input type="text" name="cid[]" value="1">
<input type="text" name="pid[]" value="2">
<input type="text" name="quantity[]" value="3">
<input type="text" name="total[]" value="5">
</form>
/*Once the form is submited the action comes to this php page*/
<?php
$cid = $_POST['cid'];
$pid = $_POST['pid'];
$quantity = $_POST['quantity'];
$total = $_POST['cid'];
$insertquery = "INSERT INTO orders(cid,pid,quantity,total) VALUES('$cid','$pid','$quantity','$total')";
?>
/*After excution of this code only inseting the last value, not inserting the all value */
【问题讨论】:
-
然后遍历数组。
-
@u_mulder。但是我从不同的名称获取表单值,所以我该如何迭代它。
-
您的脚本对SQL Injection Attack 甚至if you are escaping inputs, its not safe! 都是开放的,在
MYSQLI_或PDOAPI 中使用prepared parameterized statements