Jump to content

Recommended Posts

[code]
<?

if (!isset($_GET['page'])) {
  include ("home.html");
} else {                         <-------- Line 36
  if ($_GET['page'] != (home|contracts|reminders|accessories|contactus) {
    include ("home.html");
  } else {
    $page = $_GET['page'];
    include ("/content/".$page.".html");
  }
}

?>
[/code]

to me that looks fine, but when i test it, it comes up and says "Parse error: syntax error, unexpected '}' in C:\website\index.php on line 36" [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] i marked line 36 in the code

any help appreciated
Link to comment
https://forums.phpfreaks.com/topic/12970-problem-with-a-simple-if-statement/
Share on other sites

You forgot to close the expression bracket in the second if statment.
The code should be this:
[code]
<?

if (!isset($_GET['page'])) {
  include ("home.html");
} else {                         <-------- Line 36
  if ($_GET['page'] != (home|contracts|reminders|accessories|contactus) ) {
    include ("home.html");
  } else {
    $page = $_GET['page'];
    include ("/content/".$page.".html");
  }
}

?>
[/code]
try this ok
[code]
<?

if (!isset($_GET['page'])) {


  include ("home.html");

} elseif ($_GET['page'] != (home|contracts|reminders|accessories|contactus) {


    include ("home.html");

} else {

    $page = $_GET['page'];

    include ("/content/".$page.".html");

}


?>
[/code]

thanks for the help, the code works now. i also have one other question. right now i am passing variable in the URL using /index.php?page=home but i have seen people use /index.php?home if i use the second script, how do i retrieve the variable home.
I don't know if I have this right, but I will try to explain as I understand it.

If you use /index.php?home you setting the $_GET['home'] variable to NULL. If you use /index.php?page=home your are setting the $_GET['page'] variable to 'home'. I would say the /index.php?page=home is better, but If you want to use the /index.php?home method, try this:
[code]

if (
    isset($_GET['home']) |
    isset($_GET['contracts']) |  
    ....
    isset($_GET['contactus'])
   )
{
include ("home.html");
}
else
{
// the rest of your code....
}
[/code]
i redesigned the code to use the index.php?home format and this is what i came up with

[code]<?

if (!isset($_GET)) {
  include ("home.html");
} elseif (isset($_GET['home'])) {            <--------Line 37
  include ("home.html");
} elseif (isset($_GET['contracts'])) {
  include ("contracts.html");
} elseif (isset($_GET['reminders'])) {
  include ("reminders.html");
} elseif (isset($_GET['accessories'])) {
  include ("accessories.html");
} elseif (isset($_GET['contactus'])) {
  include ("contactus.html");
} else {
  include ("home.html");
}

?>
[/code]

it looks good to me but now i got a new issue, the error is almost the same: "Parse error: syntax error, unexpected '{' in C:\Inetpub\PMPOOLS\index.php on line 37"

its as if it is not accepting the elseif statement isn't there so it is not expecting the condition that follows it. any reasons why it would do that?
[code]
<?

if (! isset($_GET)) {

  include ("home.html");

} elseif (isset($_GET['home'])) {    
        
  include ("home.html");

} else { $_GET['contracts'];

  include ("contracts.html");

} elseif (isset($_GET['reminders'])) {

  include ("reminders.html");

} else { $_GET['accessories'];

  include ("accessories.html");

} elseif (isset($_GET['contactus'])) {

  include ("contactus.html");

} else {

  include ("home.html");
}

?>
[/code]
Try this way or your have to alter it to the first old way ok.

[code]
<?

if (! isset($_GET)) {

  include ("home.html");

} elseif (! isset($_GET['home'])) {    
        
  include ("home.html");

} else { $_GET['contracts'];

  include ("contracts.html");

} elseif (! isset($_GET['reminders'])) {

  include ("reminders.html");

} else { $_GET['accessories'];

  include ("accessories.html");

} elseif (! isset ($_GET['contactus'])) {

  include ("contactus.html");

} else {

  include ("home.html");
}

?>
[/code]
Whats a mess! redarrow I suggest your go back to the manual and readup on if/elseif/else statements!

As this:
} else { $_GET['accessories'];
does nothing!

Also soccerstar22003 you might be better of with a switch statment instead:
[code]<?php

// check that p is set in the URL
if (isset($_GET['p']))
{
    // now we include the correct page
    switch($_GET['p'])
    {
        case 'home':
            include 'home.html';
        break;

        case 'contacts':
            include 'contacts.html';
        break;

        case 'reminders':
            include 'reminders.html';
        break;

        case 'accessories':
            include 'accessories.html';
        break;

        case 'contactus':
            include 'contactus.html';
        break;

        default:
            include 'home.html';
        break;
    }
}
?>
<a href="?p=home">Home</a> | <a href="?p=contacts">Contacts</a> | <a href="?p=reminders">Reminders</a> | <br />
<a href="?p=accessories">Accessories</a> | <a href="?p=contactus">Contact Us</a> | <a href="?p=contactus">Contact Us</a>[/code]
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.