Jump to content

[SOLVED] Parse error. Please Help


paulman888888

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/113736-solved-parse-error-please-help/
Share on other sites

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
?>

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.

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.";
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.