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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...