Two forms on one page - THE ANSWER
am 05.01.2011 05:56:06 von Ethan RosenbergJim -
Much thanks to you for solving a problem with which I have been
struggling for the last two weeks.
Here is the code:
===========
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
switch ( @$_POST['next_step'] )
{
case 'step1':
echo 'Your kittens name is '.htmlspecialchars($_POST['cat']);
echo <<
FORM;
break;
case 'step2':
if ( empty($_POST['dob']) )
die('DOB was not set in session...');
if ( !preg_match('!^\d{2}/\d{2}/\d{4}$!', $_POST['dob'], $m) )
die('DOB was not properly formated, please try again.');
// calculate timestamp corresponding to date value
$dateTs = strtotime($_POST['dob']);
// calculate timestamp corresponding to 'today'
$now = strtotime('today'); $dateArr = explode('/', @$_POST['dob']);
// check that the value entered is a valid date
if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
die('ERROR: Please enter a valid date of birth');
// check that the date entered is earlier than 'today'
if ( $dateTs >= $now )
die('ERROR: Please enter a date of birth earlier
than 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 approximately $ageYears years and $ageMonths
months old.";
break;
case 'step1':
default:
echo <<
FORM;
}
?>
=========
Ethan
MySQL 5.1 PHP 5.3.3-6 Linux [Debian (sid)]
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php