Я задал этот вопрос раньше. Но он обновляется с помощью ajax и добавляется в корзину.
У меня есть форма, которая имеет некоторые поля ввода и также имеет некоторые поля флажков. Если кто-то заполнит поля и установите флажок, а затем отправьте. Затем некоторые данные в соответствии с представлением отображаются на другом div.
Теперь, если тот же человек снова заполнит эти поля после первого представления и установите флажок и отправьте. Затем некоторые данные в соответствии с представлением отображаются на div. Но он заменяет старый контент для представления. Мне нужно все содержимое для отправки, в div, включая все содержимое старого представления.
Мой код:
<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:
<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>
Мой ajax_cart.php:
<?php include"connection.php"; $action = $_REQUEST['action']; @$p_id = trim($_REQUEST['p_id']); //$_SESSION['product_cart'] = array(); if($action == 'add'){ @$quantity = $_REQUEST['quantity']; if(!empty($p_id)){ $query1=mysql_query("select * from lab_location_package_rel where id='$p_id'") or die (mysql_error()); while($product_data = mysql_fetch_assoc($query1)) { $mrp=$product_data['mrp']; $opp=$product_data['offer_price_perc']; $package_id=$product_data['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); } $product = array("p_id"=>$product_data['id'],"title"=>$value2['package_title'],"price"=>$product_data['mrp']*$quantity,"image"=>$product_data['offer_price_perc']); if(isset($_SESSION['product_cart']) && !empty($_SESSION['product_cart'])) { if(!array_key_exists($product_data['id'],$_SESSION['product_cart'])) { $_SESSION['product_cart'][$product_data['id']] = $product; } } else{ $_SESSION['product_cart'][$product_data['id']] = $product; } } } if($action == "delete"){ unset($_SESSION['product_cart'][$p_id]); } if($action == "empty"){ session_destroy(); } ?> <div class="cart_data"> <?php if(isset($_SESSION['product_cart'])){ foreach($_SESSION['product_cart'] as $data){ ?> <h5>Patient Details</h5> <table class="table table-bordered"> <tbody> <tr> <th>Name</th> <th>Age</th> <th>Sex</th> <th></th> </tr> <tr> <?php //if(isset($_POST["submit"])==true) { ?> <td><?php //echo $_POST['name1']; ?></td> <td><?php //echo $_POST['age']; ?></td> <td><?php //echo $_POST['selectgender']; ?></td> <td><a href="#" class="btn btn-info">Update</a></td> </tr> </tbody></table> <br><br> <h5>Package Details</h5> <table class="table table-bordered"> <tbody> <tr> <th>Package</th> <th>MRP</th> <th>Offer Price</th> <th></th> </tr> <tr> <td><?php echo $data['title']; ?></td> <td><strike><?php echo $data['price']; ?></strike></td> <td><?php echo $data['image']; ?></td> <td>Delete</td> </tr> <?php } ?> </tr> </tbody></table> <?php } } ?> </div>
-<?php include"connection.php"; $action = $_REQUEST['action']; @$p_id = trim($_REQUEST['p_id']); //$_SESSION['product_cart'] = array(); if($action == 'add'){ @$quantity = $_REQUEST['quantity']; if(!empty($p_id)){ $query1=mysql_query("select * from lab_location_package_rel where id='$p_id'") or die (mysql_error()); while($product_data = mysql_fetch_assoc($query1)) { $mrp=$product_data['mrp']; $opp=$product_data['offer_price_perc']; $package_id=$product_data['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); } $product = array("p_id"=>$product_data['id'],"title"=>$value2['package_title'],"price"=>$product_data['mrp']*$quantity,"image"=>$product_data['offer_price_perc']); if(isset($_SESSION['product_cart']) && !empty($_SESSION['product_cart'])) { if(!array_key_exists($product_data['id'],$_SESSION['product_cart'])) { $_SESSION['product_cart'][$product_data['id']] = $product; } } else{ $_SESSION['product_cart'][$product_data['id']] = $product; } } } if($action == "delete"){ unset($_SESSION['product_cart'][$p_id]); } if($action == "empty"){ session_destroy(); } ?> <div class="cart_data"> <?php if(isset($_SESSION['product_cart'])){ foreach($_SESSION['product_cart'] as $data){ ?> <h5>Patient Details</h5> <table class="table table-bordered"> <tbody> <tr> <th>Name</th> <th>Age</th> <th>Sex</th> <th></th> </tr> <tr> <?php //if(isset($_POST["submit"])==true) { ?> <td><?php //echo $_POST['name1']; ?></td> <td><?php //echo $_POST['age']; ?></td> <td><?php //echo $_POST['selectgender']; ?></td> <td><a href="#" class="btn btn-info">Update</a></td> </tr> </tbody></table> <br><br> <h5>Package Details</h5> <table class="table table-bordered"> <tbody> <tr> <th>Package</th> <th>MRP</th> <th>Offer Price</th> <th></th> </tr> <tr> <td><?php echo $data['title']; ?></td> <td><strike><?php echo $data['price']; ?></strike></td> <td><?php echo $data['image']; ?></td> <td>Delete</td> </tr> <?php } ?> </tr> </tbody></table> <?php } } ?> </div>
с<?php include"connection.php"; $action = $_REQUEST['action']; @$p_id = trim($_REQUEST['p_id']); //$_SESSION['product_cart'] = array(); if($action == 'add'){ @$quantity = $_REQUEST['quantity']; if(!empty($p_id)){ $query1=mysql_query("select * from lab_location_package_rel where id='$p_id'") or die (mysql_error()); while($product_data = mysql_fetch_assoc($query1)) { $mrp=$product_data['mrp']; $opp=$product_data['offer_price_perc']; $package_id=$product_data['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); } $product = array("p_id"=>$product_data['id'],"title"=>$value2['package_title'],"price"=>$product_data['mrp']*$quantity,"image"=>$product_data['offer_price_perc']); if(isset($_SESSION['product_cart']) && !empty($_SESSION['product_cart'])) { if(!array_key_exists($product_data['id'],$_SESSION['product_cart'])) { $_SESSION['product_cart'][$product_data['id']] = $product; } } else{ $_SESSION['product_cart'][$product_data['id']] = $product; } } } if($action == "delete"){ unset($_SESSION['product_cart'][$p_id]); } if($action == "empty"){ session_destroy(); } ?> <div class="cart_data"> <?php if(isset($_SESSION['product_cart'])){ foreach($_SESSION['product_cart'] as $data){ ?> <h5>Patient Details</h5> <table class="table table-bordered"> <tbody> <tr> <th>Name</th> <th>Age</th> <th>Sex</th> <th></th> </tr> <tr> <?php //if(isset($_POST["submit"])==true) { ?> <td><?php //echo $_POST['name1']; ?></td> <td><?php //echo $_POST['age']; ?></td> <td><?php //echo $_POST['selectgender']; ?></td> <td><a href="#" class="btn btn-info">Update</a></td> </tr> </tbody></table> <br><br> <h5>Package Details</h5> <table class="table table-bordered"> <tbody> <tr> <th>Package</th> <th>MRP</th> <th>Offer Price</th> <th></th> </tr> <tr> <td><?php echo $data['title']; ?></td> <td><strike><?php echo $data['price']; ?></strike></td> <td><?php echo $data['image']; ?></td> <td>Delete</td> </tr> <?php } ?> </tr> </tbody></table> <?php } } ?> </div>