samedi 20 juin 2020

php multiple if statements

I have the below code which is a form calculating a human body measurement. It works fine, but i want to add a condition (additional if statement).

<html>

<?php
function abi($height, $weight, $waist) {
    $height = floatval($height);
    $weight = floatval($weight);
    return $weight / ($height * $waist);
}
?>

<head>
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
    <form action="" method="POST">
        <h4>BMI</h4>
        <input id="height" name="height" type="text" placeholder="height in meters or feet" value="<?php echo isset($_POST['height']) ? $_POST['height'] : ''; ?>" />
        <br/><br/>
        <input id="weight" name="weight" type="text" placeholder="weight in kgs or lbs" value="<?php echo isset($_POST['weight']) ? $_POST['weight'] : ''; ?>" />
        <br/><br/>
        <input id="waist" name="waist" type="text" placeholder="waist in cm" value="<?php echo isset($_POST['waist']) ? $_POST['waist'] : ''; ?>" />
        <br/><br/>
        <input class="submit" type="submit" value="Submit"/>

<?php //handles if empty or 0 input
if (!empty($_POST['height']) && !empty($_POST['weight']) 
    && !empty($_POST['waist'])) : 
?>

    <p id="result">Your score is <?php echo abi($_POST['height'], $_POST['weight'], $_POST['waist']); ?></p>

<?php 
endif; 
?>

</form>
</body>
</html>

The condition i want to add is if $height x $weight is less than abi then return warning msg "weight too low". Otherwise return abi as normal.

Aucun commentaire:

Enregistrer un commentaire