Showing posts with label age calculator in php. Show all posts
Showing posts with label age calculator in php. Show all posts

Thursday, March 5, 2015

Age Solver in PHP

In this short article I would like to share with you a sample program that I wrote using PHP I called this program Age Solver. The purpose of this program will determine the age of the person by asking the person to enter the month, day and year which the person is being born. It will return the current age of the person once the user select the check age button. In addition I also add clear button which enables the user to erase the previous values and provide new birth date values in our text box.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program


Program Listing

<html>
<title> Age Solver</title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>
<?php
error_reporting(0);
$month = $_REQUEST['month'];
$day   = $_REQUEST['day'];
$year  = $_REQUEST['year'];

function age_solver($month,$day,$year) {
    list($cYear, $cMonth, $cDay) = explode("-", date("Y-m-d"));
    return ( ($cMonth >= $month && $day >= $day) || ($cMonth > $month) ) ? $cYear - $year : $cYear - $year - 1;
}

if(isset($_POST['submit'])) {
$result = "<center> Your age today is  " .age_solver($month,$day,$year)." years old.</center>";
}
if(isset($_POST['clear'])) {
 $result="";  $month="";  $day=""; $year=""; 
}
?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center"> Age Solver</h2>
  <br>
<form action="" method="post">
<center>
Month<input name="month" type="text" id="month" value="<?php echo $month ?>" size="2" maxlength="2" required autofocus>
Day<input name="day" type="text" id="day" value="<?php echo $day ?>" size="2" maxlength="2" required>
Year<input name="year" type="text" id="year" value="<?php echo $year ?>" size="2" maxlength="4" required>
<br><br>
  <input type="submit" name="submit" value="Check Age" title="Click here to know your age."> 
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
  </center>
</form><br>
<?php echo $result; ?>
</div>
</body>
</html>