Show DevBest Calculator

Status
Not open for further replies.

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
I made this little calculator, uses GET form method.
Here you go:
Index.html
HTML:
<form name="input" action="calc.php" method="get">
First Number: <input type="text" name="num1" /><br />
Second Number: <input type="text" name="num2" /><br />
<input type="radio" name="calc" value="d" />Division<br />
<input type="radio" name="calc" value="m" />Multiplaction<br />
<input type="radio" name="calc" value="a" />Add<br />
<input type="radio" name="calc" value="s" />Subtract<br />
<input type="submit" value="Calculate" />
</form>
Calc.php
PHP:
<?
$num1 = $_GET['num1'];
$num2 = $_GET['num2'];
$calc = $_GET['calc'];
if ($calc == 'd') {
$div = $num1 / $num2;
echo $div;
}
if ($calc == 'm') {
$mul = $num1 * $num2;
echo $mul;
}
if ($calc == 'a') {
$add = $num1 + $num2;
echo $add;
}
if ($calc == 's') {
$sub = $num1 - $num2;
echo $sub;
}
?>
Made it like 5 seconds
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Looks cool. Try indenting the code to make it look neater.

Also, use <?php, not ?>. Some web-servers don't have the short-tag <? enabled so the code won't execute.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
Looks cool. Try indenting the code to make it look neater.

Also, use <?php, not ?>. Some web-servers don't have the short-tag <? enabled so the code won't execute.
oh xD, sorry I forgot all about that, thanks for the tip!
 
Status
Not open for further replies.

Users who are viewing this thread

Top