Simple calculator using php script

Simple calculator using php script.

In this tutorial of php script, we are going to create a very basic and simple calculator by using php script.

<html>
<head>
<title>My simple calculator in php</title>
</head>
<body>
<form>
<input type="text" name="num1" placeholder="Number 1"></input>
<input type="text" name="num2" placeholder="Number 2"></input>
<select name="choice">
<option>None</option>
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Divide</option>
</select>
<br>
<button type="submit" name="submit" value="submit">Calculate</button>
</form>
<?php echo "Answer is  : ";?>
<?php
if(isset($_GET['submit']))
{
$number1 = $_GET['num1'];
$number2 = $_GET['num2'];
$op = $_GET['choice'];
switch ($op) {
case "None":
echo "Plese select any operation.";
break;
case "Add":
echo $number1 + $number2;
break;
case "Subtract":
echo $number1 - $number2;
break;
case "Multiply":
echo $number1 * $number2;
break;
case "Divide":
echo $number1 / $number2;
break;
}
}
?>
</body>
</html>

Output.

php simple calculator