Skip to content
Advertisement

PHP; how do I sum a variable after $POST with issest [closed]

I have a massive file with a few variable I would like to sum(add) after they are POST.

I should note that I am doing this in TCPDF. I don’t know if it makes a difference. Nonetheless, The variables I am trying to sum are being posted via an isset function. After the variables are posted, I declared a new variable. Example $sum = $two+$three+$four+$five;. However, when I do this I get an undefined variable error. Ideally, I would like declare a new variable that takes the summed values and placed them in a HTML string in my TCPDF file. for example

Total: $sum

//var_dump($_POST);
if (isset($_POST)) {

  if(isset($_POST['two'])){ $two = $_POST['two'];}else{$two = " ";}
    if(isset($_POST['three'])){ $three = $_POST['three'];}else{$three = " ";}

    if(isset($_POST['four'])){ $four = $_POST['four'];}else{$four = " ";}
    if(isset($_POST['five'])){ $five = $_POST['five'];}else{$five = " ";}
    if(isset($_POST['six'])){ $six = $_POST['six'];}else{$six = " ";}
    if(isset($_POST['seven'])){ $seven = $_POST['seven'];}else{$seven = " ";}
    if(isset($_POST['eight'])){ $eight = $_POST['eight'];}else{$eight = " ";}
    if(isset($_POST['nine'])){ $nine = $_POST['nine'];}else{$nine = " ";}
    if(isset($_POST['ten'])){ $ten = $_POST['ten'];}else{$ten = " ";}
    if(isset($_POST['elve'])){ $elve = $_POST['elve'];}else{$elve = " ";}
    if(isset($_POST['twelv'])){ $twelv = $_POST['twelv'];}else{$twelv = " ";}

Advertisement

Answer

Maybe try one at at time. Its tedious but i think it might work.

$sum = $one + $two;
$sum = $sum +$three;`

`

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement