PDA

View Full Version : PHP Calculator (here how to create)


Hackr
09-07-2006, 05:40 PM
Make a working calculator using PHP.
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 } ?>

Done.