I make an ajax from another page to my php script and it does some computations on the result obtained there and then return those values.
<form id="couponForm">
Apply coupon: <input type="text" name="addCode" placeholder="Apply Coupon">
<input class="button" style="margin-left:10px;" type="submit" value="Apply">
</form>
<script>
$('#couponForm').on('submit',function(e){
e.preventDefault();
var formData=$(this).serialize();
var totalPrice=<?php if(isset($total))echo $total;else echo'"'.'"';?>;
formData=formData+'&totalPrice='+totalPrice;
$.ajax({
url:'/cart/couponAjax.php',
type:'POST',
dataType:'json',
data:formData,
success: function (content) {
//something
}
});
})
</script>
The above page calls a php script which looks like this
require 'config.php';// contains db credentials
$totalPrice=$_POST['totalPrice'];
$couponName=mysqli_real_escape_string($mysqli,$_POST['addCode']);
$state=$mysqli->prepare('select * from `coupons` where `name`=?');
$state->bind_param('s',$couponName);
$state->execute();
$result=$state->get_result();
// $result returns everything as null.
When i check the value obtained in the $result
, it shows me something like this
DB Looks something like this
I am stuck in this thing for hours , what am i doing wrong here ?
Update: