paulman888888 Posted July 8, 2008 Share Posted July 8, 2008 Here is my code <?php $allowedPages = array('home', 'contact', 'about', 'artists'); for ($i =0; $i < sizeof($allowedPages); $i++) { if ($_GET['where'] == $allowedPAges[$i]) include $_GET['where'] . '.php'; } else{//this is line 54 echo "Page not found or allowed."; } ?> And the error Parse error: parse error, unexpected T_ELSE in /home/www/MYSITE.com/index.php on line 54 Please tell me what i have done wrong. Thankyou Paul Quote Link to comment https://forums.phpfreaks.com/topic/113736-solved-parse-error-please-help/ Share on other sites More sharing options...
rhodesa Posted July 8, 2008 Share Posted July 8, 2008 you don't have an open brace at the end of the if to match the one before the else: <?php $allowedPages = array('home', 'contact', 'about', 'artists'); for ($i =0; $i < sizeof($allowedPages); $i++) { if ($_GET['where'] == $allowedPAges[$i]){ include $_GET['where'] . '.php'; } else{//this is line 54 echo "Page not found or allowed."; } } //You were also missing one here ?> Quote Link to comment https://forums.phpfreaks.com/topic/113736-solved-parse-error-please-help/#findComment-584477 Share on other sites More sharing options...
KevinM1 Posted July 8, 2008 Share Posted July 8, 2008 Your if-statement doesn't have an opening brace. Use: $allowedPages = array('home', 'contact', 'about', 'artists'); for($i = 0; $i < sizeof($allowedPages); $i++) { if($_GET['where'] == $allowedPages[i]) { include $_GET['where'] . '.php'; } else { echo "Page not found or allowed."; } } Just so you know, your code will echo "Page not found or allowed." if your $_GET value is anything other than 'home.' So, if the 'artists' page is accessed, that error message will appear three times. Quote Link to comment https://forums.phpfreaks.com/topic/113736-solved-parse-error-please-help/#findComment-584481 Share on other sites More sharing options...
rhodesa Posted July 8, 2008 Share Posted July 8, 2008 agreed...looks like you want something more like: <?php $allowedPages = array('home', 'contact', 'about', 'artists'); if(in_array($_GET['where'],$allowedPages)){ include $_GET['where'] . '.php'; }else{ echo "Page not found or allowed."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113736-solved-parse-error-please-help/#findComment-584482 Share on other sites More sharing options...
DarkWater Posted July 8, 2008 Share Posted July 8, 2008 Yeah, you should definitely not use a for loop for something like that. rhodesa had it with in_array(). And you should really indent your code better, it'll help you see syntax errors like that. Quote Link to comment https://forums.phpfreaks.com/topic/113736-solved-parse-error-please-help/#findComment-584491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.