Beginner Bob Posted April 25, 2017 Share Posted April 25, 2017 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 More sharing options...
Larry Posted April 28, 2017 Share Posted April 28, 2017 You're missing a closing brace after line 38 that completes the IF POST['year'] Link to comment Share on other sites More sharing options...
Necuima Posted May 3, 2017 Share Posted May 3, 2017 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 More sharing options...
Beginner Bob Posted May 4, 2017 Author Share Posted May 4, 2017 I see it now, feeling pretty stupid. I checked it over 20 times! Thanks for the reply. Thanks for the tip Necuima, will save me a lot of stress in the future! Link to comment Share on other sites More sharing options...
Larry Posted May 6, 2017 Share Posted May 6, 2017 Happens to us all! Link to comment Share on other sites More sharing options...
Recommended Posts