Location: PHPKode > scripts > Calorie Burning Calculator > calorie-burning-calculator/calorie-burning-calculator.php
<?php
	include('calorie_burning_calc_files/functions.php');
	
	if ($_POST['action'] == 'calculate_bmr') {
		if (!checkValidChars($_POST['age'],"0123456789")) {
			$error_div .= getResultDiv('Please enter only numbers for your age');
		} elseif (strlen($_POST['age']) < 1) {
			$error_div .= getResultDiv('Please enter your age');
		}
		if (!checkValidChars($_POST['weight'],"0123456789")) {
			$error_div .= getResultDiv('Please enter only numbers for your weight');
		} elseif (strlen($_POST['weight']) < 1) {
			$error_div .= getResultDiv('Please enter your weight');
		}
		$result_div .= $error_div;
		if ($error_div == '') {
			$w = $_POST['weight'] * .45359237;
			if ($_POST['sex'] == 'male') {
				if ($_POST['age'] >= 0 && $_POST['age'] <= 17) {
					$bmr = 17.7 * $w + 657;
				} elseif ($_POST['age'] > 17 && $_POST['age'] <= 29) {
					$bmr = 15.1 * $w  + 692;
				} elseif ($_POST['age'] > 29 && $_POST['age'] <= 99) {
					$bmr = 11.5 * $w + 873;
				}
			} else {
				if ($_POST['age'] >= 0 && $_POST['age'] <= 17) {
					$bmr = 13.4 * $w + 692;
				} elseif ($_POST['age'] > 17 && $_POST['age'] <= 29) {
					$bmr = 14.8 * $w  + 487;
				} elseif ($_POST['age'] > 29 && $_POST['age'] <= 99) {
					$bmr = 8.3 * $w + 846;
				}
			}
			$bmr = round($bmr);
			$result_table = '
				<div class="bmr-result-div"><h1>Your estimated daily metabolic rate is <strong>' .$bmr . '</strong></h1><p>This means that you need roughly ' . $bmr . ' calories a day to maintain your current weight</p></div>
										</td>
									</tr>
								</table>
							</div>
				</table>';
		}
	}
	if ($result_table == '') {
		$result_table = '<p>The results of your calculation will display here.</p>';
	}
?>
<html>
<head>
<title>Quick Health Calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="calorie_burning_calc_files/styles.css" rel="stylesheet" type="text/css"></link>	
<script type="text/javascript" src="calorie_burning_calc_files/js_include.js"></script>
</head>

<body>
	<div class="banner align-center"><a href="http://www.my-health-and-fitness.org"><img src="quickcalc/banner.jpg" alt="My Health and Fitness.org" /></a></div>
	<h1>Calorie Burning Calculator</h1>
	<?php echo $result_div; ?>
	<p>Use the Calorie Burning Calculator to calculate your basal metabolic rate (BMR), which is the number of calories you burn on a daily basis. Note that this equation only gives a rough estimate. Depending on your activity level, you may require more or less calories.</p>
	<form action="calorie-burning-calculator.php" onsubmit="return checkform(this);"   method="post">
		<input type="hidden" name="action" value="calculate_bmr" />
		<table class="wide">
			<tr>
				<td class="third-width"></td>
				<td>
					<div class="outer-calc">
					<table class="wide calc-table">
						<tr>
							<td class="align-right">Sex:</td>
							<td>
								<select name="sex"><option value="female">Female</option><option value="male">Male</option></select></td>
						</tr>
						<tr>
							<td class="align-right">Age:</td>
							<td><input type="text" size="2" name="age" value="<?php echo $_POST['age']; ?>" /> years</td>
						</tr>
						<tr>
							<td class="align-right">Weight:</td>
							<td><input type="text" size="5" name="weight" value="<?php echo $_POST['weight']; ?>" /> lbs</td>
						</tr>
						<tr>
							<td class="align-center" colspan="2"><input type="submit" value="Calculate &gt;" /></td>
						</tr>
					</table>
					</div>
					<div class="acknowledgement">
						Powered by <a href="http://www.my-health-and-fitness.org">www.My-Health-And-Fitness.org</a>
					</div>
				</td>
				<td class="third-width"></td>
			</tr>
		</table>	
	</form>
	<hr />
	<?php echo $result_table; ?>
	<hr />
	<p><strong>&copy;<?php echo date('Y'); ?> <a href="http://www.my-health-and-fitness.org">www.My-Health-And-Fitness.org</a></strong></p>
</body>
</html>
Return current item: Calorie Burning Calculator