Paulio Posted September 19, 2008 Share Posted September 19, 2008 Hey, im having some trouble with my code, ive been using the php "switch", i used the free hosting from lycos while i tested the website and all was fine (using "index.php?x=corporate" etc...), now i have changed to a proper cpanel webhost (has php) the page always comes up with the "default" code i.e. default: echo("<div class='title'>Home</div>"); include("content_home.php"); } below is the code from my page and any help would be much appreciated. thanks, Paul <html> <head> <title>test.com</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="script.js"></script> </head> <body> <?php switch ($x) { case corporate: echo("<div class='title'>Corporate</div>"); include("content_corporate.php"); break; case business: echo("<div class='title'>Business</div>"); include("content_business.php"); break; case gallery: echo("<div class='title'>Gallery</div>"); include("content_gallery.php"); break; case weddings: echo("<div class='title'>Wedding Car Service</div>"); include("content_weddings.php"); break; case contact: echo("<div class='title'>Contact Us</div>"); include("content_contact.php"); break; case contactform: echo("<div class='title'>Contact Form</div>"); include("content_contactform.php"); break; case sent: echo("<div class='title'>Message Sent</div>"); include("content_sent.php"); break; default: echo("<div class='title'>Home</div>"); include("content_home.php"); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/ Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 Add quotes around all of your possibilities. case "corporate": Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645784 Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 The only time you don't need quotes is for integers. Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645789 Share on other sites More sharing options...
Paulio Posted September 19, 2008 Author Share Posted September 19, 2008 i have now used quotes and it didnt do anything <?php switch ($x) { case "corporate": echo("<div class='title'>Corporate</div>"); include("content_corporate.php"); break; case "business": echo("<div class='title'>Business</div>"); include("content_business.php"); break; case "gallery": echo("<div class='title'>Gallery</div>"); include("content_gallery.php"); break; case "weddings": echo("<div class='title'>Wedding Car Service</div>"); include("content_weddings.php"); break; case "contact": echo("<div class='title'>Contact Us</div>"); include("content_contact.php"); break; case "contactform": echo("<div class='title'>Contact Form</div>"); include("content_contactform.php"); break; case "sent": echo("<div class='title'>Message Sent</div>"); include("content_sent.php"); break; default: echo("<div class='title'>Home</div>"); include("content_home.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645791 Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 What do you get if you echo $x before the switch? Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645793 Share on other sites More sharing options...
papaface Posted September 19, 2008 Share Posted September 19, 2008 switch ($x) should be: switch ($_GET['x']) Also you dont need () for echos (although theres technically nothing wrong with using them.) echo "something"; will suffice. Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645796 Share on other sites More sharing options...
Paulio Posted September 19, 2008 Author Share Posted September 19, 2008 switch ($x) should be: switch ($_GET['x']) Also you dont need () for echos (although theres technically nothing wrong with using them.) echo "something"; will suffice. this sorted it, for some reason it worked on lycos though ??? also for some reason putting echo $x wouldnt let the page load at all, even with the changes in this post :S Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645804 Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 for some reason it worked on lycos though Don't see how this is possible if $x isn't even defined... Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645807 Share on other sites More sharing options...
Paulio Posted September 19, 2008 Author Share Posted September 19, 2008 thanks alot for the help though guys, fixed super quick Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645811 Share on other sites More sharing options...
papaface Posted September 19, 2008 Share Posted September 19, 2008 The reason it works on lycos is because they're using register_globals which is bad basically Quote Link to comment https://forums.phpfreaks.com/topic/124981-solved-help-with-quotswitchquot/#findComment-645818 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.