1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | <?php if($_POST!=null) { $h=empty($_POST["height"]) ? 0 : $_POST["height"]; $w=empty($_POST["weight"]) ? 0 : $_POST["weight"]; $index =0; if($h !=0 && $w !=0) $index = round($w/($h*$h)* 703,2); $bmi=""; $bmiStyle="alert alert-primary"; if ($index < 18.5) { $bmi="underweight - BMI : " . $index; $bmiStyle="alert alert-secondary"; } else if ($index < 25) { $bmi="normal - BMI : ". $index; $bmiStyle="alert alert-success"; } else if ($index < 30) { $bmi="overweight - BMI : " . $index; $bmiStyle="alert alert-warning"; } else { $bmi="obese - BMI : " .$index; $bmiStyle="alert alert-danger"; } } ?> <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title> CODE4EXAMPLE </title> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <h1>PHP BODY MASS INDEX (BMI)</h1> <form method="post"> <div class="form-group"> <label for="height">Please Enter your Height in Inches :</label> <input type="text" class="form-control" name="height" placeholder="69"> </div> <div class="form-group"> <label for="weight">Please Enter your weight in Pounds :</label> <input type="text" class="form-control" name="weight" placeholder="150"> </div> <div class="form-group"> <button type="submit" class="btn btn-success">Calculate</button> </div> </form> <div class="<?=$bmiStyle?>" role="alert" id="bmi"> <?php echo $bmi; ?> </div> </div> </body> </html> |

How to Calculate BMI(Body Mass Index) Using PHP With HTML Form
You May Also Like: