PHP – Simple Addition Function

Code Example: 
<?php
if(isset($_POST['sum1']) && isset($_POST['sum2']))
{
	$sum1 = $_POST['sum1'];
	$sum2 = $_POST['sum2'];
	
	function add($sum1,$sum2)
	{
		$answer = $sum1 + $sum2;
		
		if(!is_numeric($sum1) || !is_numeric($sum2))
		{
			return 'Please enter a number nob!';
		}
		
		echo $sum1 . ' + ' . $sum2 . ' = ' . $answer;
	}	
	
	echo add($sum1,$sum2);
}

?>

<form method="post" action="#">
	<input type="text" name="sum1" value="" /><br />
	<input type="text" name="sum2" value="" /><br />
	
	<input type="submit" name="submit" value="Add" />
</form>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *