Jump to content
Larry Ullman's Book Forums

Chapter 6 - Nesting Conditionals


Recommended Posts

Hi,
 
I seem to be having problems with nesting conditionals. I have followed through the steps in the book, but have come across the following error:
 
Parse error: syntax error, unexpected 'else' (T_ELSE) in /Applications/MAMP/htdocs/sites/PHPbook/Chapter6/handle_reg.php on line 39
 

Line 39 relates to the second else statement. What have I done wrong?

if ( is_numeric($_POST['year']) AND (strlen($_POST['year']) == 4) ) {
        if ($_POST['year'] < 2017) {
          $age = 2017 - $_POST['year'];
        } else {
          print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>';
          $okay = false;
    } else {
          print '<p class="error">Please enter the year you were born as four digits.</p>';
          $okay = false;
        }
      }

 

Link to comment
Share on other sites

As an aside, I always nest braces aligned top with bottom and indented so that you can easily see where they start and end.  It seems that this is not a common approach but I have found it very helpful in complex nesting situations.

 

For what it's worth...

 

Cheers 

Link to comment
Share on other sites

 Share

×
×
  • Create New...