I am new to PHP and I'm doing simple exercises to try to fully understand each thing I learn. I can confidently output data inputted from a form but for this particular exercise I can't see where I am going wrong. The form is currently outputting '1'.
I am trying to build a BMI calculator, any help is appreciated, thank you in advance.
My form
<?php
return "
<p>Calculate your BMI</p>
<form method='post' action='index.php?page=process-bmi'>
<p>Please enter your height and weight to calculate your BMI</p>
<label for='height'>Height</label>
<input type='text' id='height' name='height'>
<label for='weight'>Weight</label>
<input type='text' id='weight' name='weight'>
<input type='submit' value'Submit' name='bmi-submitted'>
</form>";
My php is
<?php
$bmiSubmitted = isset($_POST['bmi-submitted']);
if ($bmiSubmitted) {
$weight = $_POST['weight'];
$height = $_POST['height'];
$output = bmi($weight, $height);
}
function bmi($weight, $height) {
$bmi = $weight/($height*$height);
$response = "<p>Your bmi is $bmi</p>";
return $response;
}
?>
