This tutorial will teach you how to make a calculator using PHP.
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