Basic calculator php

 <!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Learning</title>
</head>
<body>
<form method="GET">
<label>First num: </label>
<input name="firstnum" type="text"/>
<label>Second num: </label>
<input name="lastnum" type="text"/>
<label>Operation</label>
<input name="operation" type="text"/>
<button type=submit>submit</button>
</form>

<?php
$first = $_GET['firstnum'];
$second = $_GET['lastnum'];
$op = $_GET['operation'];
switch($op){
case "+": echo $first + $second;
break;
case "-":echo $first - $second;
break;
case "*":echo $first * $second;
break;
case "/":echo $first / $second;
break;
default:echo "Invalid operation given please try again";
}
?>
</body>
</html>

Comments

Popular posts from this blog