title: php discount code error when wrong code entered
body: <p>I'm trying to integrate a discount code into my shopping cart. It works fine, calculates the correct discount when the code is entered, the issue I'm having when the user enters an incorrect code, the cart total just becomes £0.00. Can anyone point me in the right direction?</p>
  
  <p>javascript :</p>
  
  <pre><code>$(document).ready(function(){
  $("#addcoupon").click(function(){
      var ttlamt = $("#ttl_amount").val();
      var ccode = $("#couponcode").val();
      var cpn = ccode.replace(/\s/g, '');
      if(cpn.length &lt;= 0){
          $("#couponcode").css("border-color","red");
      }else{
        $("#couponcode").css("border-color","");
        $.ajax({
            dataType: 'json',
            url: "page.php",
            method: "POST",
            data: {action:"coupon_dis",couponval: cpn,amnt: ttlamt},
            cache: false,
            success: function(data){
              if(data != "0"){
                  $("#grandamount").css("display","none");
                  $("#discount_amount").css("display","none");
                  $("#couponcode").css("border-color","green");
                  $("#grand_discount_amount").css("display","block");
                  $("#final_discount_amount").css("display","block");
                  $("#grand_discount_amount").html(data.price);
                  $("#final_discount_amount").html(data.discount);
              }else{
                  $("#discount_amount").css("text-decoration","");
                  $("#grandamount").css("text-decoration","");
                  $("#couponcode").css("border-color","red");
                  $("#grand_discount_amount").css("display","none");
                  $("#final_discount_amount").css("display","none");
                  $("#grand_discount_amount").html("");
                  $("#final_discount_amount").html("");
              }
            }
        });
      }
      return false;
  });
  </code></pre>
  
  <p>page.php</p>
  
  <pre><code>if(isset($_POST['action']) &amp;&amp; $_POST['action'] == "coupon_dis")
  {
     $couponcode = trim($_POST['couponval']);
     $amnt = $_POST['amnt'];
     $val = '0';
     if($couponcode == "loyalty10"){
        $couponDiscount_val = "10";
        $discount_amount = floor($amnt*$couponDiscount_val)/100;
        $amount_after_discount = $amnt - $discount_amount;
        $val = sprintf("%01.2f", $amount_after_discount);
  }
     $_SESSION['discount_amount'] = sprintf("%01.2f", $discount_amount);
     $_SESSION['product_discount'] = $val;
  }
  
  $return = [
     'price' =&gt; $currency.$val, 
     'discount' =&gt; $minus.$currency.number_format((float)$discount_amount, 2,'.', '')
  ];
  
  header('Content-Type: application/json');
  echo json_encode($return);
  </code></pre>