Jump to content

[SOLVED] Switch function trouble.


n00bert

Recommended Posts

ok I have been using this switch function with no problems on my old server.

Now that I have switched to a new server it no longer works. So i'm almost positive it's a setting in the php.ini or something.

 

It will display the default: just fine but it will not display any of the cases..

Link to comment
Share on other sites

ummm I just figured you knew what a switch function was.. my apologies.

<?php
switch($page){
	default:
		include 'quotes.php';
	break;

	case quotes:
		include 'quotes.php';
	break;

	case msgs:
		include 'messages.php';
	break;

}
?>

Link to comment
Share on other sites

<?php
   switch($page)
   {
/*
      case "quotes":
         include 'quotes.php';
      break;
*/
      case "msgs":
         include 'messages.php';
      break;
      default:
         include 'quotes.php';   }
?>

 

Default clause should be last and doesnt require a break; after it. Assuming your cases arent testing for constants you need to quote the strings, if you were using defined constants, remove the quotes I added.

 

//* EDIT

 

No point in having a case that gives the same result as your default clause...

Link to comment
Share on other sites

ok seven you were correct. I tried to echo $page and I got nothing. So I enabled register_globals in my php.ini and now everything works.

 

Andy thanks you as well for the advice.

 

BTW.. should I not enable register globals? is there a better way around this?

Link to comment
Share on other sites

ok seven you were correct. I tried to echo $page and I got nothing. So I enabled register_globals in my php.ini and now everything works.

 

Andy thanks you as well for the advice.

 

BTW.. should I not enable register globals? is there a better way around this?

 

Yes, register_globals is BAD.

 

instead of $page use $_GET['page'] or $_POST['page']....depending on which one you're using

Link to comment
Share on other sites

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.