HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
PHP Switch error
Post new topic   Reply to topic    HTML Help Forum Index -> PHP
View previous topic :: View next topic  
Author Message
PK



Joined: 01 Feb 2006
Posts: 19

PostPosted: Tue Jun 13, 2006 9:10 am     PHP Switch error Reply with quote

I'm deveolping a PHP site, and for one of my pages I need to have multiple things in one section, changeable from URL variables. I used a switch code to do this, but I can't figure out what is wrong with my code, the variable name I used was 'page' and it should change if its value is between 1 and 3 inclusive.

Here is the page, and this is the PHP I used for the switch section:

Code:
             <?PHP
            
      //Selects what goes in the right section-variable denoted in URL
       Switch ($_Get["page"])
       {
         Case 1:
          Echo "Aditional List 1";
          Break;
         
         Case 2:
          Echo "Aditional List 2";
          Break;
         
         Case 3:
          Echo "Aditional List 3";
          Break;
         
         Default:
          Echo "Main List";
          Break;
         
      }
      ?>   


Can anyone offer any help?
Padaxes



Joined: 06 Apr 2006
Posts: 27

PostPosted: Tue Jun 13, 2006 3:00 pm     Reply with quote

try this

Code:
<?php
 
 Switch ($page)
       {
         Case '1':
          Echo "Aditional List 1";
          Break;
         
         Case '2':
          Echo "Aditional List 2";
          Break;
         
         Case '3':
          Echo "Aditional List 3";
          Break;
         
         Default:
          Echo "Main List";
          Break;
         }
         
?>
PK



Joined: 01 Feb 2006
Posts: 19

PostPosted: Wed Jun 21, 2006 8:35 am     Reply with quote

Thats fine if I have the variable declard somewere else on the page, but I wanted it to read the variable off of the URL, how would I get it to do that?

EDT:// nevermind, I got it to work using the following code:
Code:
             <?PHP        
                                      
      //Selects what goes in the right section-variable denoted in URL
       Switch ($_GET["page"])
       {
         Case '1':
          Echo "Aditional List 1";
          Break;
         
         Case '2':
          Echo "Aditional List 2";
          Break;
         
         Case '3':
          Echo "Aditional List 3";
          Break;
         
         Default:
          require ("mainlist.htm");
          Break;         
      }
      ?>

Thanks for the help.
Padaxes



Joined: 06 Apr 2006
Posts: 27

PostPosted: Wed Jun 21, 2006 12:26 pm     Reply with quote

Actually my code works if its passed in by the URL, you dont HAVE to use $_GET. At least it works for me Smile

But anyway it works for you now thats the main thing Smile
degsy



Joined: 23 Feb 2005
Posts: 2440
Location: North East, UK

PostPosted: Wed Jun 21, 2006 12:33 pm     Reply with quote

Padaxes wrote:
Actually my code works if its passed in by the URL, you dont HAVE to use $_GET. At least it works for me Smile

But anyway it works for you now thats the main thing Smile


Your PHP ini file has register_globals on. Don't rely on that. Use the superglobals such as $_POST, $_GET etc.
Padaxes



Joined: 06 Apr 2006
Posts: 27

PostPosted: Thu Jun 22, 2006 12:17 am     Reply with quote

Yeah thats the one!
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> PHP All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial