mercredi 26 juillet 2017

How to calculate the age of a user's input in years and months using php?

I have been given an assignment to build a point of sale system. The customer will be charged based on their age.If the user is older that 15.5 years they will be charge $50 for a product. If the user is younger that 15.5 years they will be charged $25.

This is the code that I have so far:

<html>
<head>
    <title>Age Test</title>
</head>
<body>

    <form action="age_test.php" method="post">

        <input type="text" name="first" placeholder="Enter first name">
        <br>
        <input type="text" name="last" placeholder="Enter last name">
        <br>
        <input type="date" name="date">
        <br>
        <label for="rush"> Check for a rush order(A $200 fee will apply.)</label>
        <input type="checkbox" name="rush">
        <br>
        <input type="submit" name="submit">
    </form>

    <?php 
        if(isset($_POST['submit'])){
            // echo "submit is set";

            $date = $_POST['date'];

            $age = date("Y/m/d") - $date;

            echo $age;

            //Users age will determine the price.
        if($age >= 15.5){

        echo "<br>Your price is $50";


        }elseif ($age < 15.5) {
            echo "<br>Your price is $25";
        }

        if(isset($_POST['rush'])){
            // echo "<br>$200 is applied to payment";
        }


        }





     ?>

</body>
</html>

The solution that I have does not give me a decimal as a result. I would like some help on how to produce a decimal as a result. Any help will be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire