Rate this script:  I Love it  /   I Hate it

PHP BMI Calculator


Code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
// BMI = ( Weight in Pounds / ( Height in inches ) x ( Height in inches ) ) x 703
if ((isset($_POST['done'])) && ($_POST['done'] == 'y')) {
$weight = $_POST['weight'];
$height_feet = $_POST['height_feet'];
$height_inches = $_POST['height_inches'];
$converted_height = ($height_feet * 12) + $height_inches;
$BMI = $weight * 703 / ($converted_height * $converted_height);
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Body Mass Index (BMI) - Calculator</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head>
<body>
<div align="center">
<form id="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
     <p><h3>Body Mass Index Calculator</h3></p>
     <p>
          <label></label><label>Height (Feet):
          <select name="height_feet" id="height_feet">
               <option selected="selected" value="<?php echo $height_feet; ?>">--- select one ---</option>
                           <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
               <option value="6">6</option>
               <option value="7">7</option>
          </select>
          </label>
          <label>Height (Inches):
          <select name="height_inches" id="height_inches" >
               <option selected="selected" value="<?php echo $height_inches; ?>" >--- select one ---</option>
                           <option value="0">0</option>
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
               <option value="4">4</option>
               <option value="5">5</option>
               <option value="6">6</option>
               <option value="7">7</option>
               <option value="8">8</option>
               <option value="9">9</option>
               <option value="10">10</option>
               <option value="11">11</option>
          </select>
          </label>
          <br />
          <label><br />
          Weight (Pounds):
          <input name="weight" type="text" id="weight" value="<?php echo $weight; ?>" size="5" maxlength="3" />
          </label>
     </p>
     <p>
          <label>BMI:
          <input  readonly="true" name="BMI" type="text" id="BMI" value="<?php echo round($BMI, 2); ?>" size="6" maxlength="4" />
          </label>
     </p>
     <p>
          <input type="submit" name="Submit" value="Calculate BMI" />
                  <input name="done" type="hidden" value="y" />
     </p>
</form>
</div>
<hr />
<h3>What your results mean:</h3>
Your height is <?php echo $height_feet; ?> feet <?php echo $height_inches; ?> inches. <br />
Your weight is <?php echo $weight; ?> lbs. <br />
Your BMI is <?php echo round ($BMI, 2); ?> <br />
<?PHP
/*
Underweight = <18.5
Normal weight = 18.5-24.9
Overweight = 25-29.9
Obesity = BMI of 30 or greater
*/

if ($BMI <= 18.5) {
echo "You are underweight.";
}
elseif (($BMI > 18.5) && ($BMI <= 24.9))
{
echo "You are at your normal weight.";
}
elseif ($BMI > 24.9 && $BMI <= 29.9)
{
echo "You are overweight.";
}
elseif ($BMI > 29.9 && $BMI <= 39.9)
{
echo "You are obese.";
}
else
{
echo "You are morbidly obese.";
}
?>
<br />
To find out more about Body Mass Index scores, see <br />
<a href="http://www.cdc.gov/nccdphp/dnpa/bmi/adult_BMI/about_adult_BMI.htm">U.S. Department of Health and Human Services:  Centers for Disease Control and prevention</a><br />
BMI for Adults<br /><br />
</body>
</html>
 

 

 
PHP BMI Calculator scripts | PHP BMI Calculator snippet | PHP BMI Calculator example | PHP BMI Calculator tutorial | PHP BMI Calculator code