Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.