Caution: Testing In Progress

We have 24, What are we putting in the fridge.



Key

The Code:

if(empty($_POST)) {
		$drinks = 24;
		$counter = 0;
		$message = "We have $drinks, What are we putting in the fridge.";
	} else {
		$status = array();
		$drinks = $_POST['drinks'];
		$drinksAdd = filter_input(INPUT_POST, 'drinksAdd', FILTER_VALIDATE_INT);
		$drinksSub = filter_input(INPUT_POST, 'drinksSub', FILTER_VALIDATE_INT);
		$counter = $_POST['counter'];
		
		if($drinksAdd === false) {
			$status[] = "You can't add that to the fridge!";	
		}
		if($drinksSub === false) {
			$status[] = "You can't take that out of the fridge!";	
		}
		
		if(isset($drinksAdd) || isset($drinksSub)) {
			$drinksCal = addDrinks($drinks, $drinksAdd, $drinksSub);
			if($drinksCal < 0) {
				$drinksNeeded = $drinksSub - $drinks;
				$drinks = 0;
				$status[] = "We'll Need $drinksNeeded more to 
							fill that order";
			} else {
				$drinks = $drinksCal;
			}
			$counter++;
			$status[] = "We have $drinks in the fridge
						and it's been opened $counter times.";
		}
	
		$message = '';
		foreach($status as $messages) {
			$message .= "$messages 
"; } } function addDrinks($current, $toAdd, $toSub) { $newDrinks = $current + $toAdd; $newDrinks = $newDrinks - $toSub; return $newDrinks; }