PHP - Programming Language
This course covers the basics of programming in PHP. Work your way through the videos and we'll teach you everything you need to know to start your programming journey!

Building A Better Calculator

Lesson 22
Author : Mike Dane
Last Updated : November, 2017


Code

site.phpCopy
<form action="site.php" method="GET"> Num1: <input type="number" name="num1"> Operator: <input type="text" name="op"> Num2: <input type="number" name="num2"> <input type="submit"> </form> <?php $num1 = $_GET["num1"]; $num2 = $_GET["num2"]; $op = $_GET["op"]; if($op == "+"){ echo $num1 + $num2; } elseif($op == "-"){ echo $num1 - $num2; } elseif($op == "/"){ echo $num1 / $num2; } elseif($op == "*"){ echo $num1 * $num2; } else { echo "Invalid Operator"; } ?>