Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,466 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,410 people online right now. Registration is fast and FREE... Join Now!




Switch Error

 
Reply to this topicStart new topic

Switch Error

aswettla
post 14 Apr, 2005 - 03:08 PM
Post #1


D.I.C Addict

****
Joined: 27 Sep, 2002
Posts: 603



Thanked 1 times
My Contributions


Hi,

I'm using the following code to produce a index.php?p=contact style thingy. Here is my code, then I try to run index.php?p=contact i get the following error.

QUOTE

Parse error: parse error, unexpected T_VARIABLE, expecting '(' in c:\program files\easyphp1-7\www\czeg\index.php on line 2


my code:

CODE
<?php
switch $_GET['p']
{
   case "login":
       include('login.php');
       break;
   case "news":
       include('news.php');
       break;
   case "pilots":
       include('pilots.php');
       break;
   default:
       include('main.php');
}
?>


Could somebody please help!

This post has been edited by aswettla: 14 Apr, 2005 - 03:08 PM
User is offlineProfile CardPM

Go to the top of the page

supersloth
post 14 Apr, 2005 - 03:16 PM
Post #2


serial frotteur

Group Icon
Joined: 21 Mar, 2001
Posts: 19,514



Thanked 11 times

Dream Kudos: 2147483647

Expert In: being gentlemanly

My Contributions


wouldnt you be better served just doing include('$_GET['p'].php'); ???
User is online!Profile CardPM

Go to the top of the page

aswettla
post 14 Apr, 2005 - 03:19 PM
Post #3


D.I.C Addict

****
Joined: 27 Sep, 2002
Posts: 603



Thanked 1 times
My Contributions


Super, now I fixed it up using your suggestion and I get this error.

Parse error: parse error, unexpected T_CASE in c:\program files\easyphp1-7\www\czeg\index.php on line 4
User is offlineProfile CardPM

Go to the top of the page

supersloth
post 14 Apr, 2005 - 03:23 PM
Post #4


serial frotteur

Group Icon
Joined: 21 Mar, 2001
Posts: 19,514



Thanked 11 times

Dream Kudos: 2147483647

Expert In: being gentlemanly

My Contributions


i dunno i probably didn't use the correst syntax for the get, i usually just use $p, maybe someone else can help with the correct syntax since i'm at work and don't have access to a php enabled box.
User is online!Profile CardPM

Go to the top of the page

Amadeus
post 14 Apr, 2005 - 03:42 PM
Post #5


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


Try
CODE

include($_GET['p'].".php");
User is offlineProfile CardPM

Go to the top of the page

snoj
post 14 Apr, 2005 - 05:21 PM
Post #6


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


Just fixing your original code.
CODE

<?php
//You need teh parentheses '(' and ')'.
switch($_GET['p'])
{
  case "login":
      include('login.php');
      break;
  case "news":
      include('news.php');
      break;
  case "pilots":
      include('pilots.php');
      break;
  default:
      include('main.php');
}
?>


Also note that while Sloth's and Amadeus' code is simpler (and far easier to do) they also open up scripts that you may not want people to see/use. But that's just what I think. And it depends on alot of things.


Oh and before I click 'Add Reply'.
CODE

<?php
//If you'd like to check if $_GET['p'] is valid.
$page = ($_GET['p'] == ('login'||'news'||'pilots')) : $_GET['p'] ? 'main';
include($page.'.php');
?>


This post has been edited by hotsnoj: 14 Apr, 2005 - 05:22 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:42PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month