In: Computer Science
According to researchers at Stanford Medical School (as cited in Medical Self Care), the ideal weight for a woman is found by multiplying her height in inches by 3.5 and subtracting 108. The ideal weight for a man is found by multiplying his height in inches by 4 and subtracting 128. Using PHP and HTML 5, design and build a web page that calculates the ideal weight given the person’s gender and height. The user selects the gender from a drop down list and enters the height in a text box. Your PHP script should read all the input and calculate and display the ideal weight.
Answer:
Code:
<html>
<head>
<title>Weight Calculator</title>
</head>
<body>
<form method="post">
<label>Enter Your Height:</label>
<input type="number" step="0.01" id="height" name="height"
required><br><br>
<label>Choose Your Gender:</label>
<select required id="gender" name="gender">
<option disabled selected>Select Gender</option>
<option>Male</option>
<option>Female</option>
</select><br><br>
<input type="submit" name="test" id="test" value="Calculate"
/><br/>
</form>
<?php
function testfun()
{
if(isset($_POST["test"]))
{
$H=$_POST["height"];
$G=$_POST["gender"];
if($G=="Male")
{
$M=($H*4)-128;
}
if($G=="Female")
{
$M=($H*3.5)-108;
}
echo "<p> Your Weight is :".$M."</p>";
}
}
if(array_key_exists('test',$_POST)){
testfun();
}
?>
</body>
</html>
Input and Output:


DO UPVOTE ME IF IT HELPS