<?php
include('includes/header.php');
error_reporting(E_ALL); // show all errors
echo('<h1>Nataliia\'s BMI Calculator</h1>');
$step = isset($_POST['step']) ? $_POST['step'] : 0;
$weight = isset($_POST['weight']) ? $_POST['weight'] : '';
$height = isset($_POST['height']) ? $_POST['height'] : '';
$step = htmlentities($step);
$weight = htmlentities($weight);
$height = htmlentities($height);
if ($step == 0) // first time in form
{
?>
<form action="bmi.php" method="POST">
<label for="weight">Weight (lbs)</label>
<input type="text" size="10" id="weight" name="weight" value="">
<br><br>
<label for="height">Height (ft)</label>
<input type="text" size="10" id="height" name="height" value="">
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
else
{
echo('<p>The following is what the form gathered</p>');
echo('<pre>');
print_r($_POST);
echo('</pre>');
// convert height in feet to inches
$heightInches = $height * 12;
// BMI formula for lbs/inches: (weight / (height^2)) * 703
$bmi = ($weight / ($heightInches * $heightInches)) * 703;
echo("<h3>Your BMI = $bmi</h3>");
?>
<form action="bmi.php" method="POST">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('includes/footer.php');
?>