jquery - Ajax PHP update using 2 query -


im trying update reserve table column additional ill value table price multiply quantity post problem can't update heres code

for form php

  <form method="post">                <div class="col-md-12">                 <label>id</label>                 <input type="text" class="form-control" id="id" name="id">               </div>                <div class="col-md-12" >                 <label>charge</label>                 <select id="name" name="name" class="form-control">                   <?php                   while ($reserve=mysqli_fetch_array($charge)) { ?>                     <option value=" <?php echo $reserve['name']?>">                       <?php echo $reserve['name']; ?>                     </option><?php } ?>                 </select>               </div>                <div class="col-md-12">                 <br>                 <label>quantity</label>                 <input type="number" class="form-control" id="quantity" name="quantity">               </div>                <div class="col-md-12">                 <br>                 <button class="huge ui teal button" id="charge" name="charge">add charge</button>               </div>              </form> 

for ajax

  $(document).ready(function(e){   $('#charge').click(function(){   var id = $('#id').val();   var name = $('#name').val();   var quantity = $('#quantity').val();           $.ajax({            type   : 'post',            data   :{               id:id,               name:name,               quantity:quantity,                   },             url     :"charge.php",             success : function(result){               if(result)               {                  $('#error').html("<span class='text-success' >success man</span>");              }else{                $('#error').html("<span class='text-danger'>check mo information man</span>");            }           }          })     });   }); 

and charge.php

<?php  $connect = mysqli_connect("localhost", "root", "", "tobedetermined");     $id = $_post['id'];    $name = $_post['name'];    $quantity = $_post['quantity'];     $sql = "select price charge name ='$name'";    $result = $connect->query($sql);    $additional = $result * $quantity;   mysqli_query($connect,"update reserve set additional= '$additional' id = $id");    mysqli_close($connect);   ?> 

please don't mind select tag used put value of column name frm charge table

if want use ajax, not use form.

just remove form tag

<div class="col-md-12">                 <label>id</label>                 <input type="text" class="form-control" id="id" name="id">               </div>                <div class="col-md-12" >                 <label>charge</label>                 <select id="name" name="name" class="form-control">                   <?php                   while ($reserve=mysqli_fetch_array($charge)) { ?>                     <option value=" <?php echo $reserve['name']?>">                       <?php echo $reserve['name']; ?>                     </option><?php } ?>                 </select>               </div>                <div class="col-md-12">                 <br>                 <label>quantity</label>                 <input type="number" class="form-control" id="quantity" name="quantity">               </div>                <div class="col-md-12">                 <br>                 <button class="huge ui teal button" id="charge" name="charge">add charge</button>               </div> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -