i am sending 5 different data across to a php file through POST method. the data is all integers. i want to add up all these integer values to produce a sum.
$.post(
"user_submit.php",
{score: $('#ques'+qn).find('input[name=vote]:checked').val() },
function(data){
$("#ques"+qn).hide();
++qn;
$("#ques"+qn).show();
});
});
in the php file:
$score = $_POST['score'];
$total = $total + $score;
echo $total;
it is not adding up the values. what am i doing wrong?
If you were to
print_r($_POST['score']), you would see that it’s actually an array, not a single value. Try something like$total += array_sum($_POST['score']);instead.