Jump to content
Larry Ullman's Book Forums

sworden

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by sworden

  1. Thanks. That should have occurred to me. I've gotten it to work, sort of. If I try to intentionally trigger an error I get the error message (Either you entered...) up through 2037(using April 3 as the month and day). Using a 2038 year date the code

    print "<p>You will turn $age this year.</p>";
    

    gives me "You will turn -26 this year."

    Here is the pertinent code:

    //Check that they were born before the current day
    $current_year = date('Y');
    $today  = new DateTime();
    $birthday = strtotime($_POST['month']."/".$_POST['day']."/".$_POST['year']);
    if ($birthday < $today->getTimestamp()) {
    	$age = $current_year - $_POST['year'];
    	//Calculate age this year
    } else {
    	print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>';
    	$okay = FALSE;
    } //End of 2nd conditional
    
    } else { //Else for 1st conditional
    
    print '<p class="error">Please enter the year you were born as four digits.</p>';
    $okay = FALSE;
    
    } //End of 1st conditional
    

    What am I doing wrong?

  2. For the fifth task I tried:

    //Validate Day
    if (empty($_POST['day'])) {
    print '<p class="error">Please enter a value for day</p>';
    $okay = FALSE;
    }
    //Validate Month
    if (empty($_POST['month'])) {
    print '<p class="error">Please enter a value for month</p>';
    $okay = FALSE;
    }
    
    //Validate the birth year  
    if (is_numeric($_POST['year']) AND (strlen($_POST['year']) == 4) ) {
    
    //Check that they were born before the current day
    $current_year = date('Y');
    $today  = date( "n/j/Y");
    $birthday = $_POST['month']."/".$_POST['day']."/".$_POST['year'];
    if ($birthday < $today) {
    	$age = $current_year - $_POST['year'];
    	//Calculate age this year
    } else {
    	print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>';
    	$okay = FALSE;
    } //End of 2nd conditional
    
    } else { //Else for 1st conditional
    print '<p class="error">Please enter the year you were born as four digits.</p>';
    $okay = FALSE;
    

    but when I enter a valid birthday, I get this message: "Either you entered your birth year wrong or you come from the future!" so my conditional ($birthday < $today) is coming back false when it shouldn't. What am I doing wrong?

×
×
  • Create New...