unexpected T_ELSEIF [closed]


$pages = array("grac", "zamknij", "dolaczyc"); $pagesid = array("showNews", "showThread", "showProfile"); foreach ($pagesid as $page) { if (isset($_GET[$page])) { include('sobra/'.$page.'.php'); } } // just pages elseif (in_array($_GET['page'], $pages)) { include("$_GET[page].php"); } // error else include('error.php');

gives:<br /><i>Parse error: syntax error, unexpected T_ELSEIF in C:\WAMP\www\sdgag\index.php on line 33</i>

This should work i think.. what the problem can be?



Perhaps another approach. Do your logic, and determine what page you want to include ultimately. After all of the logic has been done, include your determined page.

<em>The following is untested, and may contain errors. Let me know, and I'll update the code.</em>

<?php // Predefined list of acceptable pages $pages = array("one","two","three"); $pagesid = array("four","five","six"); // Gather any user-defined page request $desPage = trim($_GET["page"]); // Assume they are wrong, and need to see error.php $pageToLoad = "error.php"; // If the user request is not empty if (!empty($desPage)) { if (in_array($desPage,$pages)) { $pageToLoad = $desPage . ".php"; } } else { // User request is empty, check other variables foreach ($pagesid as $pageid) { if (isset($_GET[$pageid])) { $pageToLoad = $pageid . ".php"; } } } // Show output page include($pageToLoad); ?>


The elseif and the else aren't attached to the if, you've put them outside of the foreach loop block.


<strong>There is one closing bracket to much before the else.</strong>

It should read:

$pages = array("grac", "zamknij", "dolaczyc"); $pagesid = array("showNews", "showThread", "showProfile"); foreach ($pagesid as $page) { if (isset($_GET[$page])) { include('sobra/'.$page.'.php'); } // just pages else if (in_array($_GET['page'], $pages)) { include("$_GET[page].php"); } // error else include('error.php'); }

<strong>If you indent your source code correctly such errors show up fast and you can fix them yourself.</strong>


$pages = array('grac', 'zamknij', 'dolaczyc'); $pagesid = array('showNews', 'showThread', 'showProfile'); foreach ($pagesid as $page) { if (isset($_GET[$page])) { include('sobra/'.$page.'.php'); } // just pages else if (in_array($_GET['page'], $pages)) { include($_GET[$page].'.php'); // fixed missing $, restylized to match previous style } else include('error.php'); }


  • Parse error: syntax error, unexpected T_ELSEIF [closed]
  • Browser client using autobahn.js can not connect to Ratchet Websocket Server
  • PHPExcel: How to save the loaded file after changes has made on it?
  • DoDirectPayment failed: couldn't connect to host(7)
  • how to configure codeigniter mod_rewrite on wamp?
  • How to deploy django project and runtime environment with all in once click
  • CakePHP 3.0 not running without intl extension
  • Listing of folders/subfolders with RecursiveDirectoryIterator
  • Is there a way to remove '/web' from url in Symfony application without moving content of
  • how can i reference $_SERVER['DOCUMENT_ROOT'] in a .htaccess file?
  • file_get_contents with https requests via proxy
  • ZipList with Scalaz
  • Connecting bluetooth device to windows phone 8 application
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • CXF JAXB JAXBEncoderDecoder unmarshalling error : unexpected element when having qualified elements
  • Unexpected token ILLEGAL while running node.js mocha test
  • Question about instantiating object
  • PHP buffered output depending on server setting?
  • Email verification using google app script and google forms
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Using $this when not in object context
  • Master page gives error
  • Optimizing database types to compact database (SQLite)
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Cross-Platform Protobuf Serialization
  • Perl system calls when running as another user using sudo
  • Do I've to free mysql result after storing it?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Proper way to use connect-multiparty with express.js?
  • Turn off referential integrity in Derby? is it possible?
  • Can't mass-assign protected attributes when import data from csv file
  • sending mail using smtp is too slow
  • Conditional In-Line CSS for IE and Others?
  • How to load view controller without button in storyboard?