<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title> Birthday </title>
<?php
if(isset($_POST["birthday"]))
$birthday = $_POST["birthday"];
else
$birthday = 1;
function calculate_age($birthday){
list($day, $month , $year) = explode("/", $birthday);
$day_diff = date("d") - $day;
$month_diff = date("m") - $month;
$year_diff = date("Y") - $year;
if($month_diff < 0){
$year_diff--;
}
else if(($month_diff == 0) && ($day_diff < 0)){
$year_diff--;
}
else if (($month_diff == 0) && ($day_diff == 0)){
echo "<script type='text/javascript'>alert('Happy
Birthday!!!');</script>";
}
return $year_diff;
}
$finalBirthday=calculate_age($birthday);
?>
</head>
<body>
<h1>Birthday Calculator</h1>
<form name="Birthday" method="POST" action="birthday.php">
<label>What is your Birthday?</br></label>
<input type ="text" name = "birthday" VALUE = "DD/MM/YYYY"></br>
<input type ="submit" name = "submit" VALUE = "Submit"></br>
</form>
<?php
echo "Our Birthday Calculator says you are " .$finalBirthday;
?>
</body>
</html>
I was wondering why first running this it comes up with "Our Birthday Calculator says you are 2017".
After putting an actual date in, however, the php works properly.
Any help would be greatly appreciated.