-
Notifications
You must be signed in to change notification settings - Fork 3
/
bmi_calculator.php
186 lines (171 loc) · 7.09 KB
/
bmi_calculator.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.error{
color: red;
margin-left: 5px;
}
</style>
</head>
<body>
<?php
session_start();
$page ="bmi";
include "header.php";
include "breadcrumb.php";
?>
<!-- Calculate BMI Area Start -->
<section class="calculate-bmi-area">
<div class="container">
<!--Row Start-->
<div class="row">
<!-- Column Start-->
<div class="col-sm-12">
<h2 class="section-heading color-dark">What is BMI</h2>
<h3 class="section-subheading">Body mass index is a value derived from the mass and height of a person. The BMI is defined as the body mass divided by the
square of the body height, and is universally expressed in units of kg/m², resulting from mass in kilograms and height in metres</h3>
</div>
<!-- Column End-->
</div>
<!--Row End-->
<!--Row Start-->
<div class="row bmi-wrapper">
<!-- Column Start-->
<div class="col-sm-6">
<div class="bmi-box">
<h3 class="color-dark">BMI Calculator Chart</h3>
<table class="bmi-calculator-chart-table">
<tr>
<th>BMI</th>
<th >Weight Status</th>
</tr>
<tr>
<td>Below 18.5</td>
<td style="color: red;">Underweight</td>
</tr>
<tr>
<td>18.5 to 24.9</td>
<td style="color: green;">Healthy</td>
</tr>
<tr>
<td>25 to 29.9</td>
<td style="color: orange;">Overweight</td>
</tr>
<tr>
<td>30 and Above</td>
<td style="color: red;">Obese</td>
</tr>
</table>
<p><span class="bmi-star">*</span> <span class="color-dark">BMR</span> Metabolic Rate / <span class="color-dark">BMI</span> Body Mass Index</p>
</div>
</div>
<!-- Column End-->
<?php
$heightErr =$weightErr="";
$height=$weight="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["height"])) {
$heightErr = "Height is required";
} else {
$height = test_input($_POST["height"]);
}
if (empty($_POST["weight"])) {
$weightErr = "Weight is required";
} else {
$weight = test_input($_POST["weight"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!-- Column Start-->
<div class="col-sm-6">
<div class="bmi-box">
<h3 class="color-dark">Calculate Your BMI</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dui. Aenean massa.</p>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Height / cm" id="height" name="height" step="1" pattern="\d+" >
<span class="error"> <?php echo $heightErr;?></span>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="number" class="form-control" placeholder="Weight / kg" id="user-weight" name="weight" step="1" pattern="\d+" >
<span class="error"> <?php echo $weightErr;?></span>
</div>
</div>
<div class="col-sm-12">
<div class="contact-sub-btn">
<input type="submit" name="submit" value="Calculate" class="section-button btn btn-effect text-uppercase font-14 para-color">
<br>
</div>
</div>
<div class="col-sm-10 " style="margin-top: 10px;">
<?php
$bmi=$output="";
$mtheight=1;
$weight=1;
$height=1;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$weight = $_POST['weight'];
$height = $_POST['height'];
$mtheight = (int)$height/100;
if($mtheight){
function bmi($weight,$mtheight) {
$bmi = (int)$weight/($mtheight * $mtheight);
return $bmi;
}
$bmi = bmi($weight,$mtheight);
if ($bmi <= 18.5) {
$output = "Under Weight";
} else if ($bmi > 18.5 AND $bmi<=24.9 ) {
$output = "Normal Weight";
} else if ($bmi > 24.9 AND $bmi<=29.9) {
$output = "Over Weight";
} else if ($bmi > 30) {
$output = "OBESE";
}
}
}
?>
</div>
<div class="col-sm-11 alert <?php
if ($bmi <= 18.5) {
echo "alert-danger";
} else if ($bmi > 18.5 AND $bmi<=24.9 ) {
echo "alert-success";
} else if ($bmi > 24.9 AND $bmi<=29.9) {
echo "alert-warning";
} else if ($bmi > 30) {
echo "alert-danger";
}
?>">
<?php
if($height >0 && $weight >0) {
echo "Your BMI value is " . $bmi . " and you are : ";
echo "$output"; }?>
</div>
</div>
</form>
</div>
</div>
<!-- Column End-->
</div>
<!--Row End-->
</div>
</section>
<!-- Calculate BMI Area End -->
<?php include "footer.php" ?>
</body>
</html>