Will probably be a simple solution but I cannot figure out why my php switch function is not working on my site. I have just changed hosting and it was working perfectly before and Ive changed nothing and just uploaded all the files the way they should be but the function does not work. Any ideas?
It's hard to say without you code. I guess I can be wrong permissions on files or some php extentions not installed on your new hosting.
The code is <?php switch($id) { default: include('default.php'); break; case "2": include('2.php'); break; case "3": include('3.php'); break; case "4": include('4.php'); } ?> Code (markup):
i agree with faceless. try echo $id to make sure it contains a value you're expecting (and is not empty).
yes , debug a little , also remember that around integers no quotes need to be used so switch ( $id ) { case 1: // do your shit break; // etc }
buah and if ur code is this <?php switch($id) { default: include('default.php'); break; case "2": include('2.php'); break; case "3": include('3.php'); break; case "4": include('4.php'); } ?> maybe better to do something like <?php $pages = array(1,2,3,4,5); include( (isset($var) && in_array($var,$pages)) ? $var.'.php' : '1.php' );
Looks like you're expecting register_globals to be set to On. Don't rely on register_globals: it's insecure and deprecated. You'll need: $id = $_REQUEST['id']; as the first line after the opening PHP tag and that should work.