I was trying to make a calculator and wanted to use Arithmetic Operators in the switch Statement but i am not able to.
Can someone help me out.
Error:
Warning: Undefined array key "num2" in on line 16
220
Fatal error: Uncaught DivisionByZeroError: Division by zero in 27 Stack trace: #0 {main} thrown on line 27
<!DOCTYPE html>
<html>
<body>
<form action="php.php" method="post">
Number 1: <input type="number" name="num1"><br>
Operator: <input type="text" name="op"><br>
Number 3: <input type="number" name="num1"><br><br>
<input type="submit">
</form>
<?php
$num1 = $_POST["num1"];
$op = $_POST["op"];
$num2 = $_POST["num2"];
switch($op)
{
case "+":
echo $num1 + $num2;
case "-":
echo $num1 - $num2;
case "*":
echo $num1 * $num2;
case "/":
echo $num1 / $num2;
}
?>
</body>
</html>