I have been using Codeigniter for an assignment in university and I cannot seem to get this to work, any feedback and fixes are greatly appreciated. The errors returned are:
- Undefined index: submit
- Undefined variable: weight
- Undefined variable: height
- Division by zero
This is the code that doesnt work, it is a file in the views folder:
<div id="container">
<h1>BMI and Blood Pressure Calculator</h1>
<div id="body">
<p>This webpage allows users to calculate their BMI and Blood Pressure by entering in their values into the boxes</p>
</br>
<p>Please enter in your details below</p>
<form>
<br />
<br />Patient Information
<br />Height <input type="text" name="height" size="12" maxlength="20">
<br />Weight <input type="text" name="weight" size="12" maxlength="20">
<br />
<br /><input type="reset" value="Clear Form">
<br /><input type="submit" value="Submit Information">
</form>
</div>
<?php
$this->input->post('height');
$this->input->post('weight');
if ($_GET['submit']) {
$height = $_GET['height'];
$weight = $_GET['weight'];
}
function bmi($height,$weight) {
$bmi = $weight/($height*$height);
return $bmi;
}
$bmi = bmi($weight,$height);
if ($bmi <= 15) {
$output = "Very severely underweight";
} else if ($bmi > 15 AND $bmi<=16 ) {
$output = "Severely underweight";
} else if ($bmi > 16 AND $bmi<=18.5) {
$output = "Underweight";
} else if ($bmi > 18.5 AND $bmi<=25) {
$output = "Normal";
} else if ($bmi > 25 AND $bmi<=30) {
$output = "Overweight";
} else if ($bmi > 30 AND $bmi<=35) {
$output = "Obesity class 1";
} else if ($bmi > 35 AND $num<=40) {
$output = "Obesity class 2";
} else if ($bmi > 60) {
$output = "Obesity class 3";
echo "Your BMI is " . $bmi . " and you are : ";
echo "$output";
}
?>