选择查询不工作的PHP

时间:2016-09-12 20:23:07

标签: php ajax

我从另一个页面创建一个ajax到我的php脚本,然后对那里获得的结果进行一些计算,然后返回这些值。

<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>

上面的页面调用了一个看起来像这样的PHP脚本

     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.

当我检查$result中获得的值时,它会显示类似这样的内容

enter image description here

DB看起来像这样

enter image description here enter image description here

我被困在这件事中好几个小时,我在这里做错了什么?

更新

enter image description here

0 个答案:

没有答案
相关问题