Skip to content

Instantly share code, notes, and snippets.

@rapisenpai
Last active August 30, 2022 08:16
Show Gist options
  • Save rapisenpai/f00991da430fc948850d9548f0cc1e86 to your computer and use it in GitHub Desktop.
Save rapisenpai/f00991da430fc948850d9548f0cc1e86 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<style>
body{
text-align: center;
font-size: 15px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}#input{
font-size: 20px;
}#menu{
margin-top: 5px;
font-size: 20px;
padding: 2px;
}button{
background-color: #04AA6D;
border: none;
color: white;
font-size: 20px;
border-radius: 5px;
margin-top: 5px;
}button:hover{
background-color: #059862;
}
</style>
</head>
<body>
<form>
<input id="input" type="text" name="num1" placeholder="Enter a number">
<input id="input" type="text" name="num2" placeholder="Enter a number">
<select id="menu" name="operators">
<option>None</option>
<option>Add</option>
<option>Substract</option>
<option>Multiply</option>
<option>Divide</option>
<option>Modulus</option>
</select>
<br>
<button name="submit" value="submit" type="submit">Total</button>
</form>
<?php
if(isset($_GET['submit'])){
$num1 = $_GET['num1'];
$num2 = $_GET['num2'];
$operator = $_GET['operators'];
if(!is_numeric($num1) || !is_numeric($num2)) {
echo "Invalid number";
}
if(empty($num1) || empty($num2)) {
echo "<br>Please enter a number";
}
else{
switch ($operator) {
case "None":
echo "<br>Please select operator";
break;
case "Add":
echo $num1 + $num2;
break;
case "Multiply":
echo $num1 * $num2;
break;
case "Divide":
echo $num1 / $num2;
break;
case "Substract":
echo $num1 - $num2;
break;
case "Modulus":
echo $num1 % $num2;
break;
}
}
}
?>
<br>
<br>
<h2>Source Code:</h2>
<script src="https://gist.github.com/rapisenpai/f00991da430fc948850d9548f0cc1e86.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment