im trying to update the reserve table column additional where ill get the value from table price multiply by quantity from post but my problem is i can't update it heres my code
for the 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 the 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 for the charge.php
<?php
$connect = mysqli_connect("localhost", "root", "", "tobedetermined");
$id = $_POST['id'];
$name = $_POST['name'];
$quantity = $_POST['quantity'];
$sql = "SELECT price FROM charge where name ='$name'";
$result = $connect->query($sql);
$additional = $result * $quantity;
mysqli_query($connect,"update reserve set additional= '$additional' where id = $id");
mysqli_close($connect);
?>
please don't mind the Select tag i just used that to put all the value of column name frm charge table