通过添加到购物车的会话提交产品

时间:2017-12-08 12:49:13

标签: javascript php jquery mysql ajax

我之前问过这个问题。但它用ajax更新并添加到购物车。

我有一个表单,它有一些输入字段,还有一些复选框字段。如果任何一个填写字段并选择一些复选框然后提交。然后根据提交的一些数据显示在另一个div上。

现在,如果同一个人在首次提交后再次填写该字段,请选中复选框并提交。然后根据提交的一些数据显示在div上。但它取代了旧的提交内容。我需要所有提交内容,包括所有旧的提交内容。

我的代码是:

Undefined property

我的AJAX是:

<form  class="reservation-form mb-0" action="" method="post" novalidate autocomplete="off">

    <input name="name1" class="form-control required " type="text" placeholder="Enter Name" aria-required="true" required>
    <input name="age" class="form-control required " type="number" placeholder="Enter Age" aria-required="true" required>
    <select required id="selectarea" class="form-control" name="selectgender"> 
        <option>Select Gender</option>
        <option value="Male">Male</option>
        <option value="Female">Female</option>
    </select> 

    <?php
        $query1=mysql_query("select * from lab_location_package_rel where city_id='$selectcity1' AND area_id='$selectarea1' AND lab_id='$selectlab1'") or die (mysql_error());          
        while($value = mysql_fetch_array($query1)) {
            $mrp=$value['mrp'];
            $opp=$value['offer_price_perc'];
            $package_id=$value['package_id'];
            $per=$mrp*$opp/100;
            $total=$mrp-$per;
            $query2=mysql_query("select * from package_master where id='$package_id'") or die (mysql_error());
            $value2 = mysql_fetch_array($query2);
            ?>     
            <li class="list-group-item">
                <div class="checkbox">
                    <input type="checkbox" id="checkbox" name="namec[]" class="quantity<?php echo $value["id"]; ?>" value="<?php echo $value["id"]; ?>" />
                    <label for="checkbox">
                        <b>Package Name:</b> <?php $package_title1=$value2['package_title']; echo $package_title1;?> <br>
                        <b>MRP:</b>  <strike><?php $mrp1=$value['mrp']; echo $mrp1; ?>  </strike><br>
                        <b>Offer Price:</b>  <?php $total1=$total; echo $total1; ?>       
                    </label>
                </div>

            </li>
        <?php } 
    ?>
    <input type="button" class="pull-right btn btn-warning" value="Submit" onclick="add_cart('<?php echo $value["id"]; ?>')">
</form>

<div class="cart_data">
        </div>

我的ajax_cart.php是:

<script>

function add_cart(p_id=""){
var quantity = $(".quantity"+p_id).val();
$.ajax({
    type:"post",
    url:"ajax_cart.php",
    data:{action:'add',p_id:p_id,quantity:quantity},
    success:function(result){
        $('.cart_data').html(result);
    }
});
}

function remove_cart(p_id){
//alert(p_id);
$.ajax({
    type:"post",
    url:"ajax_cart.php",
    data:{action:'delete',p_id:p_id},
    success:function(result){
        $('.cart_data').html(result);
    }
});
}

function empty_cart(){
$.ajax({
    type:"post",
    url:"ajax_cart.php",
    data:{action:'empty'},
    success:function(result){
        $('.cart_data').html(result);
    }
});
}

</script>

0 个答案:

没有答案