• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[PHP]Calculator

Joined
Aug 4, 2010
Messages
572
Reaction score
177
You probably seen the thread that I made of making a calculator in the language C++.

http://forum.ragezone.com/f578/c-calculator-v2-740402/

Code:
    <html>
	<head>
		<title>PHP Calculator</title> <!Website name title!>
	</head>
    <style type="text/css">
label
{
width: 5em;
float: left;
text-align: right;
margin-right: 0.5em;
display: block
}

.submit input
{
margin-left: 4.5em;
}
input
{
color: #781351;
background: #fee3ad;
border: 1px solid #781351
}

.submit input
{
color: #000;
background: #ffa20f;
border: 2px outset #d7b9c9
}
fieldset
{
border: 1px solid #781351;
width: 20em
}

legend
{
color: #fff;
background: #ffa20c;
border: 1px solid #781351;
padding: 2px 6px
} 

    </style>
	<body>
    
     
    <form method="post" action="#">
    <fieldset>
<legend>PHP Math Calculator</legend> <!Mini box title!>
    <p>
    <label>First #:</label>
    <input type="text" name="sum1" value="" />
    </p>
     
    <p>
    <label>Math: </label> 
    <select name='calculate'>
    <option value='null'>Choose...</option>
    <option value='add'>+</option>
    <option value='multiply'>x</option>
    <option value='subtract'>-</option>
    <option value='divide'>/</option>
    </select>
    </p>
     
    <p>
    <label>Second #: </label>
    <input type="text" name="sum2" value="" />
    </p>
    <b>Answer: </b> 
<?php

if(isset($_POST['sum1']) && isset($_POST['sum2']) && isset($_POST['calculate']))
{
	$sum1 = strip_tags($_POST['sum1']);
	$sum2 = strip_tags($_POST['sum2']);
	$task = $_POST['calculate'];
	
	if(!is_numeric($sum1) || !is_numeric($sum2))
	{
		echo 'You did not enter anything.'; //Stating that the user hit submit without entering a value.
	}
	else
	{
		switch($task)  
		{
			case 'add':
				echo $sum1 + $sum2;
				break;
			case 'multiply':
				echo $sum1 * $sum2;
				break;
			case 'subtract':
				echo $sum1 - $sum2;
				break;
                       case 'divide':
                               echo $sum1 / $sum2;
                            break;
			    default:
			       echo 'OoOops!';
			       break;
		}
	}
}

?>
    <p>
    <input type="submit" name="submit" value="Calculate" />   <!The button for submiting the informaiton<!>
    </p>
    </fieldset>
    </form>
        
    	</body>
</html>
 
Last edited:
Junior Spellweaver
Joined
Apr 12, 2006
Messages
121
Reaction score
26


Btw, if I'm right the tag for HTML comments is <!-- -->