The calculation for the "female" option is found by multiplying her height in inches by 3.5 and subtracting 108. The calculation if "male" is selected will be found by multiplying his height in inches by 4 and subtracting 128. I am not sure how to translate this into a php function. This calculation is processed upon pushing a submit button. My goal is to calculate the ideal weight of the given gender and height.
Currently I am unable to display the $result. Does anyone see my error?
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<?php
if(isset($_POST['submit'])) {
$gender = isset($_POST['gender']) ? $_POST['gender']: 0;
$height = (int)$_POST['height'];
switch ($gender) {
case 2:
$result = ($height * 3.5) - 108;
break;
case 1:
$result = ($height * 4) - 128;
break;
default:
$result = 0;
}
echo "Ideal Weight:", $result;
}
?>
<html>
<div align="center">
<body>
<form name="form" method="post" action="<?php echo $PHP_SELF;?>">
Select Your Gender: <select name="gender">
<option value=""></option>
<option value="1">Male</option>
<option value="0">Female</option>
</select>
<br><br>
Enter Your Height: <input type="number" name="height">
<br><br>
<input type="submit" name="submit" value="Calculate"/>
</form>
</body>
</div>
</html>