Linden Walsh
New member
I have a form with three inputs, each with different names I want the PHP file to target. I want the php to full the info put into these fields and place them beside each other.
The form is asking form someone's date of birth, with a separate input for month, day, and year. I have the php set up to calculate someones age with a single input, but i need to have three inputs. How would I go about this? Code is below:
<?php
// if form submitted
// process form input
} else {
// split date value into components
$dateArr = explode('/', $_POST['dob']);
// calculate timestamp corresponding to date value
$dateTs = strtotime($_POST['month']); $_POST['day']); $_POST['year']);
// calculate timestamp corresponding to 'today'
$now = strtotime('today');
// calculate difference between date of birth and today in days
// convert to years
// convert remaining days to months
// print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are $ageYears years old.";
}
?>
Any help would be great, the html form input names are "month", "day", and "year". So if someone inputs say 08 for month, 11 for day, and 1985 for year, I want the php to group them together as 11081985 so their age can be calculated.
The form is asking form someone's date of birth, with a separate input for month, day, and year. I have the php set up to calculate someones age with a single input, but i need to have three inputs. How would I go about this? Code is below:
<?php
// if form submitted
// process form input
} else {
// split date value into components
$dateArr = explode('/', $_POST['dob']);
// calculate timestamp corresponding to date value
$dateTs = strtotime($_POST['month']); $_POST['day']); $_POST['year']);
// calculate timestamp corresponding to 'today'
$now = strtotime('today');
// calculate difference between date of birth and today in days
// convert to years
// convert remaining days to months
// print output
$ageDays = floor(($now - $dateTs) / 86400);
$ageYears = floor($ageDays / 365);
$ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
echo "You are $ageYears years old.";
}
?>
Any help would be great, the html form input names are "month", "day", and "year". So if someone inputs say 08 for month, 11 for day, and 1985 for year, I want the php to group them together as 11081985 so their age can be calculated.