Skip to content

Instantly share code, notes, and snippets.

@jkuip
Created September 18, 2015 15:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save jkuip/43bb6716e0e907f74b49 to your computer and use it in GitHub Desktop.
Save jkuip/43bb6716e0e907f74b49 to your computer and use it in GitHub Desktop.
Simple PHP calculator
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container" style="margin-top: 50px">
<?php
// If the submit button has been pressed
if(isset($_POST['submit']))
{
// Check number values
if(is_numeric($_POST['number1']) && is_numeric($_POST['number2']))
{
// Calculate total
if($_POST['operation'] == 'plus')
{
$total = $_POST['number1'] + $_POST['number2'];
}
if($_POST['operation'] == 'minus')
{
$total = $_POST['number1'] - $_POST['number2'];
}
if($_POST['operation'] == 'times')
{
$total = $_POST['number1'] * $_POST['number2'];
}
if($_POST['operation'] == 'divided by')
{
$total = $_POST['number1'] / $_POST['number2'];
}
// Print total to the browser
echo "<h1>{$_POST['number1']} {$_POST['operation']} {$_POST['number2']} equals {$total}</h1>";
} else {
// Print error message to the browser
echo 'Numeric values are required';
}
}
?>
<!-- Calculator form -->
<form method="post" action="calculator.php">
<input name="number1" type="text" class="form-control" style="width: 150px; display: inline" />
<select name="operation">
<option value="plus">Plus</option>
<option value="minus">Minus</option>
<option value="times">Times</option>
<option value="divided by">Divided By</option>
</select>
<input name="number2" type="text" class="form-control" style="width: 150px; display: inline" />
<input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
</form>
</div>
</body>
</html>
Copy link

ghost commented Jan 9, 2018

https://github.com/akash-mahanty/calculator
IS THE BEST CALCULATOR AVAILABLE ON GITHUB
cal

@GMD12
Copy link

GMD12 commented Aug 10, 2018

nice

@myust25
Copy link

myust25 commented Feb 6, 2019

Nice,

@ShujaShah
Copy link

Nice Ui

@roof-skills
Copy link

how to genrated

@bruhGalaxy
Copy link

yes

@rameem2003
Copy link

wow

@MrRobotIsHere
Copy link

❤️

@jrossr
Copy link

jrossr commented Apr 14, 2024

sweet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment