Switch() problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Switch() problems

Post by pinehead18 »

Code: Select all

switch ($action) {
 
	case $main:
		main();
	break;
	case $main_post:
		main_post();
	break;
}
ok, when action=main_post it displays main(); instead of main post.
If i take out case $main, it displays right.

So in other words this thing is broken and for the life of me i can't figure out why.

If you help me i will love you... Virtually.

Thanks guys
Last edited by pinehead18 on Sun Jun 10, 2007 10:12 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I think you meant..

Code: Select all

 switch ($action) {
 
        case 'main':
                main();
        break;
        case 'main_post':
                main_post();
        break;
} 
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Thanks for your response. However, when i changed it then nothing worked at all.

Suggestions?

Thanks
Anthony
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Does $action actually have a value? What is it at this point in the script?

The code example astions provided is correct, so your variable is either an empty or not a string (or not one that matches those two values).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

register_globals is probably turned off.
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post by Z3RO21 »

astions wrote:register_globals is probably turned off.
As they should never be turned on, and yes make sure that data is in the $action variable.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

what would register_globals have anything to do with this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Do you set $action? If not, everything.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

pinehead18 wrote:what would register_globals have anything to do with this?
Did you ever check to see if $action has a value?
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Ha, you ninja's rock. I just started a real job for the first time and my brain has been dead ever since.

$_GET got me going thanks guys!
Post Reply