That piece of code does its job as long i want to know the bmi. But it should also check if the formula is filled with numbers and the else statement should kick in if that is not the case. although it seems to kick in it always points out error messages like:
((this is not a duplicate of another question i was linked to. There it talks about another topic which is about new error messages but this is about how i have to write my if-else statement so the check for numeric pulls out the else statement.))
Warning: A non-numeric value encountered in C:\xampp\htdocs\workspace\4.5\Aufgabe19.php on line 15
Warning: A non-numeric value encountered in C:\xampp\htdocs\workspace\4.5\Aufgabe19.php on line 15
Warning: A non-numeric value encountered in C:\xampp\htdocs\workspace\4.5\Aufgabe19.php on line 16
which it should not do. It should just say: bitte geben sie zahlen ein, if the formular is filled with other things.
<?php
// Variablen deklararien und Werte zuweisen.
$gewicht = $_POST['gewicht'];
$koerpergroesse = $_POST['koerpergroesse'];
$bmi = 0;
$dezimal = 0;
$dezimal = ($koerpergroesse /100) * ($koerpergroesse / 100);
$bmi = $gewicht / $dezimal;
if (is_numeric($gewicht) && is_numeric($koerpergroesse)) {
if ($bmi < 18.5) {
echo "Ihr BMI beträgt: " . round($bmi,2) . "<br>";
echo "Sie haben Untergewicht.";
}
if ($bmi >= 18.5 && $bmi < 25) {
echo "Ihr BMI beträgt: " . round($bmi,2) . "<br>";
echo "Sie haben Normalgewicht.";
}
if ($bmi >= 25 && $bmi < 30) {
echo "Ihr BMI beträgt: " . round($bmi,2) . "<br>";
echo "Sie haben leichtes Übergewicht.";
}
if ($bmi >= 30 && $bmi < 40) {
echo "Ihr BMI beträgt: " . round($bmi,2) . "<br>";
echo "Sie haben starkes Übergewicht.";
}
if ($bmi >= 40) {
echo "Ihr BMI beträgt: " . round($bmi,2) . "<br>";
echo "Sie haben lebensbedrohliches Übergewicht.";
}
}
else {
echo "Bitte geben sie Zahlen ein.";
}
?>