我有两种形式正常工作,有一点我无法解决的问题。
这两种表单都在提交数据,但是当我将商品提交到购物车时,它会更新或插入我为第一项更新的数量,如果您为任何其他商品选择不同的数量并添加它将插入第一项的数量不是选定的项目数量。
多表单提交的Javascript代码
<script type="text/javascript">
submitForms = function(){
document.forms["quantity"].submit();
document.forms["submit"].submit();
}
</script>
表格#1数量
<form class="" id="<?php echo $mitem_ida; ?>" name="quantity" action="item_process.php" method="post" target="votar">
<div class="quantity-wrap">
<div class="quantity" style="margin-bottom: -12px;">
<input type="button" value="-" onclick="javascript: subtractQtyz('<?php echo $mitem_ida; ?>');" >
<input name="qtyz" type="number" readonly class="qty" id="quantityx_<?php echo $mitem_ida; ?>" value="1" />
<input type="button" value="+" onclick="javascript: document.getElementById('quantityx_<?php echo $mitem_ida; ?>').value++;">
<font style="color: black; text-shadow: 2px 2px 3px #999999;">كمية</font>
</div>
</div>
</form>
表格#2其他字段
<form class="formItem" id="<?php echo $mitem_ida; ?>" name="quantity" action="item_process.php" method="post" target="votar">
<input type="hidden" value="<?php echo $mitem_ida; ?>" name="item_id">
<input type="hidden" value="<?php echo $mitem_pricea; ?>" name="price_id">
<?php if ($detect->isMobile()) { ?>
<div class="item-price" style="background-color: green; margin-top:-35px; margin-left: 105px;">
<?php }else{ ?>
<div class="item-price" style="background-color: green; margin-top:-92px; margin-left: 105px;">
<?php } ?>
<span class="amount">
<a style="color: white;" href="#" onclick="submitForms()" >
<font style="font-size: 12px;">
<?php if ($lang == 'en') {
echo "Add To Cart";
}else{
echo "<b>أضف إلى السلة</b>";
}
?>
</font>
</a>
</span>
</div></form>
php mysql查询
if (isset($_SESSION['ses_user_id']) == true){
$ses_mem = $_SESSION['ses_user_id'];
}else{
$ses_mem = session_id();
}
$insitID = mysql_real_escape_string($_POST['item_id']); // 2nd form
$inspr = mysql_real_escape_string($_POST['item_price']); // 2nd form
$iqty = mysql_real_escape_string($_POST['qtyz']); //1st form
mysql_query("
insert into temp_cart (item_id, price_id, ses_mem, qty) values (
'".$insitID."','".$inspr."','".$ses_mem."','".$iqty."'
)
");