简体   繁体   中英

error function for add cart

I have written this code for add cart to payment. while clicking buttons that cart will be add. but I got undefined syntax error

If(isset($_POST) && ($_POST[‘GET_PAYMENT’] == ‘1’))
{

    $totalAmount = $_POST[‘GET_PAYMENT’]; //Total amount
    $checkbox_id = $_POST[‘VALUE’]; // The radio button value 

        /* Here get the amount values (3,5.5 or 10) from 

    Database based on the $checkbox_id and store it in

    $amount variable*/


    $total_amount = $amount + $totalAmount;


    Echo $total_amount;

}

I got the error on above the page also I got a error in JS function

Javascript function

Function getPaymentVal()
{

Var checkboxVal = ‘’;

checkboxVal = $("input[@name=’rmr’]:checked").val();

$.ajax({
   type: "POST",
   url: "ajax.php",
   data: "GET_PAYMENT=1&VALUE=”+ checkboxVal,
   success: function(total_amount)
   {
$(‘#totalamount’).val(total_amount);  

$(‘#repair_total_amount’).html(“Total <span class="repair-finalamount-txt">&pound;&nbsp;”+ total_amount+”</span>”);

$(function() {
  $("input[name='rmr']").change(function() {
    var val = parseInt($(this).val(), 10) ;
    alert("Typeof val: " + typeof(val));
  });
});

Can anyone re-correct my code?

You have various syntax errors, capitalization and quotes, eg '' or “” instead of '' or "" along with a missing } for your success and getPaymentVal() function overall.

The php corrected:

if(isset($_POST) && ($_POST["GET_PAYMENT"] == '1'))
{
    $totalAmount = $_POST["GET_PAYMENT"];
    $checkbox_id = $_POST["VALUE"];
    $total_amount = $amount + $totalAmount;
    echo $total_amount;
}

And the same with JavaScript:

function getPaymentVal() {
  var checkboxVal = $("input[name='rmr']:checked").val();
  $.ajax({
    type: "POST",
    url: "ajax.php",
    data: {GET_PAYMENT:1,VALUE:checkboxVal},
    success: function(total_amount) {
      $('#totalamount').val(total_amount);  
      $('#repair_total_amount').html("Total <span class='repair-finalamount-txt'>&pound;&nbsp;"+total_amount+"</span>");
      $("input[name='rmr']").change(function() {
        var val = parseInt($(this).val(), 10);
        alert("Typeof val: " + typeof(val));
      });
    }
  });
}

Also note that input[@name='rmr'] should be input[name='rmr'] unless you're using jQuery < 1.3, in which the @ was removed from attribute selectors .

Check if all your brakets match, uncomment parts of the code where you think that there might be an error. Put parts of the code back in, until you notice that the error occurs. The latest added part of the code is the area where the error occurs.

This is the ways of the debugging jedi. May the force be with you.

write your 'if' statement in small letters, 'function' as well, as well as 'var', same goes for 'echo'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM