-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmi.php
More file actions
46 lines (45 loc) · 1.32 KB
/
bmi.php
File metadata and controls
46 lines (45 loc) · 1.32 KB
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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>BMI</title>
</head>
<body>
<form method="POST" action="licz.php" id="formularz" name="formularz">
<input type="number" min="40" max="560" name="waga" placeholder="Wpisz wagę w kg" id="waga" size="15">
<br>
<input type="number" min="100" max="250" name="wzrost" id="wzrost" placeholder="Wpisz wzrost w cm" size="15">
<input type="submit" value="Przelicz" id="guzik">
</form>
<?php
function licz($w, $h)
{
return $w/(($h/100.0)*($h/100.0));
}
function opis($bmi)
{
if($bmi<16) return "Anoresksja";
else if ($bmi<18) return "Niedożywienie";
else if ($bmi<25) return "Prawidłowo";
else return "Otyłość";
}
if (isset($_POST["waga"]) && !empty($_POST["waga"]) && isset($_POST["wzrost"]) && !empty($_POST["wzrost"]))
{
$waga=$_POST["waga"];
$wzrost=$_POST["wzrost"];
$bmi= licz($waga,$wzrost);
echo "<h3>Twoje BMI wynosi: ".$bmi."</h3>";
echo "<h4>Opis: ".opis($bmi)."</h4>";
}
else
{
header("Location: index.php");
}
?>
</body>
</html>