Write a PHP script to accept a weight in kg and Height in meter of person and then calculate BMI.||EasyCoding45
In this Tutorial we are going to learn how we can Write a PHP script to accept a weight in kg and Height in meter of person and then calculate BMI.
BMI= weight in Kg/ (Height in meter)2.
If BMI is in following categories , then display message accordingly(by using concept of self processing form) Underweight = <18.5 , Normal weight = 18.5–24.9 ,Overweight = 25–29.9 ,Obesity = BMI of 30 or greater.
Program ::--
<html>
<head>
<title>BMI </title>
<body>
<form action="<?php echo$_SERVER['PHP_SELF']?>" method="POST">
Enter Weight in KG :<input type=text name=t1><br>
Enter Height in meter :<input type=text name=t2><br>
<input type=submit value="CalculateBMI"><br>
</form>
<?php
if(isset($_POST['t1']))
{
$w=$_POST['t1'];
$h=$_POST['t2'];
$bmi=$w/($h*$h);
if($bmi<=18.5)
echo "Under Weight ";
else if($bmi>18.5&&$bmi<=24.9)
echo "Normal Weight ";
else if($bmi>=25&&$bmi<=29.9)
echo "Over Weight ";
else
echo "Obesity ";
}
?>
</body>
</html>
Output::--
Comments
Post a Comment