Jump to content


Photo

problem with a simple if statement


  • Please log in to reply
10 replies to this topic

#1 soccerstar22003

soccerstar22003
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 June 2006 - 11:23 PM

<?

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");
  }
}

?> 

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

#2 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 26 June 2006 - 11:30 PM

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

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");
  }
}

?> 

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 June 2006 - 11:30 PM

try this ok
<?

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");

}


?> 


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 soccerstar22003

soccerstar22003
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 June 2006 - 11:42 PM

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.

#5 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 26 June 2006 - 11:58 PM

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:

if (
    isset($_GET['home']) |
    isset($_GET['contracts']) |   
    ....
    isset($_GET['contactus'])
   )
{
include ("home.html");
}
else
{
 // the rest of your code....
}

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#6 soccerstar22003

soccerstar22003
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 June 2006 - 02:50 AM

i redesigned the code to use the index.php?home format and this is what i came up with

<? 

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");
}

?>

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?

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 June 2006 - 03:42 AM

<? 

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");
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 soccerstar22003

soccerstar22003
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 June 2006 - 03:48 AM

i tried that and i got the same problem.

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 June 2006 - 04:14 AM

Try this way or your have to alter it to the first old way ok.

<? 

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");
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 27 June 2006 - 04:47 AM

What the?

You cannot mix elseif, else elseif else. Its...
if () {
  } elseif () {
  } elseif () {
  } else {
}


#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 June 2006 - 09:36 AM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users