NewBee wants help in simple code.

I am making a simple calculator that takes input from user in two fields and then echo the result. But when i try to do it i got code printed on the page after clicking on submit button.

my HTML code is below

CALCULATOR

Enter Your Desired Values

Number 1:

Number 2:

+ - x /

and the PHP code is.

<?php $num1 = $_POST['num1']; $num2 = $_POST['num2']; $operation = $_POST['operation']; if($operation === '+'){ $result = $num1 + $num2; echo $result; } if($operation === '-'){ $result = $num1 - $num2; echo $result; } if($operation === 'x'){ $result = $num1 * $num2; echo $result; } if($operation === '/'){ $result = $num1 / $num2; echo $result; } ?>

i dont know why its not working but my xampp is working fine. Plz help

Hello,

I tried your code and, at least for me, it works as intended. What is happening on your end that’s preventing it from working? Are you receiving errors? What code is being printed after you hit submit? Once you provide that piece of information I will be able to help you.

Cheers!

Sponsor our Newsletter | Privacy Policy | Terms of Service