Return to Snippet

Revision: 44246
at April 8, 2011 06:45 by JonnySnip3r


Initial Code
<?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 'Fuck you, you dirty little cunt!';
	}
	else
	{
		switch($task)
		{
			case 'add':
				echo $sum1 . ' + ' . $sum2 . ' = ' . $sum1 + $sum2;
				break;
			case 'multiply':
				echo $sum1 . ' x ' . $sum2 . ' = ' . $sum1 * $sum2;
				break;
			case 'subtract':
				echo $sum1 . ' - ' . $sum2 . ' = ' . $sum1 - $sum2;
				break;
			default:
				echo 'Get fucked!';
				break;
		}
	}
}

?>

<form method="post" action="#">
	
	<p>
		<label>First Number: </label>
		<input type="text" name="sum1" value="" />
	</p>

	<p>
		<select name='calculate'>
			<option value='null'>Choose...</option>
			<option value='add'>+</option>
			<option value='multiply'>x</option>
			<option value='subtract'>-</option>
		</select>
	</p>
	
	<p>
		<label>Second Number: </label>
		<input type="text" name="sum2" value="" />
	</p>
	
	<p>
		<input type="submit" name="submit" value="Calculate" />
	</p>
</form>

Initial URL

                                

Initial Description
Simple as pie and chips...

Initial Title
Simple calculate script

Initial Tags

                                

Initial Language
PHP