dimanche 25 octobre 2015

How to echo out to user if date is equal to their birthday?

so for one of my school assignments I've been having troubles echoing out to the user after they have inputed their birthday. I have to echo out to the user 2 ways. 1) if the date equals their birthday they get a nice message, and 2) if the date does NOT equal their birthday then they get a different message.

For some reason my if statement isn't working... Help?

Here's the if statement........

<?php    

//if statement for birthday
$month = $_POST['month'];
$year = $_POST['year'];
$day = $_POST['day'];

$date = $year ."-". $month ."-".$day;

$date = date("Y-m-d",strtotime($date));

if(date('m-d') == date('m-d', $date)) {
    // today is users birthday. show any message you want here.
    echo "<p>Happy Birthday $firstname!</p>\n";
 } else {
    echo "<p>You were born $date.</p>\n";
 }

?>

And... Here's the drop down lists....

<?php
            $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

            //1950 is standard year thing for most websites I've noticed
            $yearFrom = 1950; // The first year included in the drop-down for years


            // $yearFrom = date("Y")-80; 
            // Using this line instead, gives a dynamic range of years, always 80 years
            // Echo out all years via a for-loop
            //<select> IS the dropdown box
            echo "<select name=\"year\" id=\"year\">";
            //less than or equal to current year
            for ($yearFrom; $yearFrom <= date("Y"); $yearFrom++) {
                    // Each $yearFrom represents a year, always incremented by 1 year
                    //echos out every year that we put present.......
                    echo "<option value=\"$yearFrom\">$yearFrom</option>";
            }
            echo "</select>";


            // Echo out all months from the array $months
            echo "<select name=\"month\" id=\"month\">";
            foreach($months as $key=>$value) {
                    // $key is the index of the array, starting at 0
                    $numericMonth = $key + 1;
                    echo "<option value=\"$numericMonth\">$value</option>";
            }
            echo "</select>";


            // Echo out all days (1-31) via a for-loop
            echo "<select name=\"day\" id=\"day\">";
            for ($i=1; $i <= 31; $i++) {
                    // Each $i represents a numeric value of days, from 1-31
                    echo "<option value=\"$i\">$i</option>";
            }
            echo "</select>";

            ?>

So... Thats what I have.. All ideas and assistance is greatly appreciated. :)

Aucun commentaire:

Enregistrer un commentaire