{source}
<form action="" method="post">
<h3>Make sure you are not obese!</h3>
<table>
<tr><td>Your weight [kg]</td><td><input type="text" name="weight" id="" /></td></tr>
<tr><td>Your height [cm]</td><td><input type="text" name="height" id="" /></td></tr>
<tr><td><input type="reset" value="Reset Numbers" /></td><td><input type="submit" name="submit" value="Let's Calculate" /> <a href="/index.php/php/bmi-calculator/php-bmi-source" target="_self">view PHP source code</a></td></tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$weight = $_POST['weight'];
$weight = preg_replace('/,/', '.', $weight); # change decimal point from Polish to English
$height = $_POST['height'];
$height = preg_replace('/,/', '.', $height); # change decimal point from Polish to English
if (($weight > 0) and ($height > 0))
{
$bmi = $weight/($height/100)**2;
$bmi = sprintf("%.2f", $bmi);
echo "<h3>Your BMI = $bmi</h3>";
if ($bmi <18.5)
{
echo "You are <b>underweight</b> according to WHO Obesity Scale.<br>You should increase your daily caloric intake and preferably see a doctor!";
}
else if ($bmi >=18.5 and $bmi <=25)
{
echo "You are within the <b>normal range</b> according to WHO Obesity Scale.<br>Congratulations!";
}
else if ($bmi >25 and $bmi <=30)
{
echo "You are <b>overweight</b> according to WHO Obesity Scale.<br>You should exercise more and possibly change your diet.";
}
else if ($bmi >30 and $bmi <=35)
{
echo "You are <b>obese</b> according to WHO Obesity Scale.<br>You should go on a diet!";
}
else
{
echo "You are <b>severely obese</b> according to WHO Obesity Scale.<br>You should go to the doctor ASAP!";
}
}
}
else
{
# echo "<h3><br></h3><br><br>";
}
echo "<p><img src=\"/images/health/BMI.png\" alt=\"Photo by unknown author\" vspace=\"3\" /></p>\n";
?>
{/source}