Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
if (isset($_POST['submit'])) {
$gender = $_POST['gender'];
$age = $_POST['age'];
$length = $_POST['length'];
$weight = $_POST['weight'];
$bmi = calculateBMI($length, $weight);
$type = calculateType($bmi);
include 'db.php';
echo addResult($gender, $age, $length, $weight, $bmi, $type);
$_SESSION['bmi'] = $bmi;
$_SESSION['type'] = $type;
$_SESSION['gender'] = $gender;
$_SESSION['age'] = $age;
$_SESSION['length'] = $length;
$_SESSION['weight'] = $weight;
header('Location: index.php');
}
header('Location: index.php');
function calculateBMI($length, $weight)
{
$bmi = round(($weight / ($length * $length)) * 10000, 1);
return $bmi;
}
function calculateType($bmi)
{
$height_data_male = array(
"ondergewicht" => array(0, 18.9),
"gezond" => array(19, 24.9),
"overgewicht" => array(25, 29.9),
);
$type = "unset";
// Iterate through the array to find the correct range
foreach ($height_data_male as $category => $range) {
// Check if the BMI falls within the range
if ($bmi >= $range[0] && $bmi <= $range[1]) {
// If it does, assign the category to $type
$type = $category;
break; // Exit the loop once a match is found
}
}
return $type;
}