This tutorial will teach you how to make a calculator using PHP.
- Learning PHP, MySQL, JavaScript, and CSS
- Programming PHP
- PHP and MySQL Web Development
- PHP for the Web: Visual QuickStart Guide
- The Joy of PHP
- PHP and MySQL for Dynamic Web Sites
- PHP Cookbook
- PHP & MySQL: The Missing Manual
Firstly, create a new .php document and copy/paste the following code into it.
|
<?php
/* Calculator */ if($submit) { if($operator == '*') { echo $numa * $numb; } elseif($operator == '/') { echo $numa / $numb; } elseif($operator == '+') { echo $numa + $numb; } elseif($operator == '-') { echo $numa - $numb; } } else { ?> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="text" name="numa" size="10"> <input type="text" name="operator" size="2"> <input type="text" name="numb" size="10"> <input type="submit" value="Calculate" name="submit"> </form> <?php } ?> |
Legend:
* Multiply
- Subtract
/ Divide
+ Add
