PHP switch is not working -
i have made calculator in php using post , 2 params - num1
, num2
. when want calculates numbers answer not showing.
should do?
here code:
if ($_post) { $first_number = $_post['first_number']; $second_number = $_post['second_number']; $cal = $_post['cal']; switch ('$cal') { case "addition": $result = $first_number + $second_number; break; case "subtraction": $result = $first_number - $second_number; break; case "multiplication": $result = $first_number * $second_number; break; case "division": $result = $first_number / $second_number; break; case "modulation": $result = $first_number % $second_number; break; } return $result; } echo "$cal <br /> <br /> 1st number: $first_number <br /> 2nd number: $second_number <br /><br />"; echo "answer is:" . $result;
you need remove quotes switch statement
replace
switch ('$cal')
with
switch ($cal)
Comments
Post a Comment