someguy9 Posted December 3, 2007 Share Posted December 3, 2007 Well I have a index.php page with a content.php script included in it and this is my content.php <? $page = htmlspecialchars($_GET['page']); ;switch($page) { case 'home': include('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); ; break; } ?> This is the script I always used and now when I use it on my new layout it jsut doesn't work... I know that the GET Page is working but it seems only to include home.php. Anyone know whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/ Share on other sites More sharing options...
therealwesfoster Posted December 3, 2007 Share Posted December 3, 2007 why is there a semi-colon in front of your switch statement? take that out change ;switch($page) to switch($page) Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404647 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 tried it still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404665 Share on other sites More sharing options...
therealwesfoster Posted December 3, 2007 Share Posted December 3, 2007 Maybe try accessing the $_GET directly, without the htmlspecialchars() just to see what it does Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404671 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 got rid of the htmlspecialcharas and it lets the 360news to work but noting else Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404683 Share on other sites More sharing options...
therealwesfoster Posted December 3, 2007 Share Posted December 3, 2007 <?php $page = $_GET['page']; switch($page) { case 'home': include('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); break; } ?> if your code looks like that and doesnt work still... then i dont know :-\ Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404690 Share on other sites More sharing options...
btherl Posted December 3, 2007 Share Posted December 3, 2007 Try printing page before the switch, like this: print "page: " . urlencode($page); Is it what you thought it would be? Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404699 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 just prints page: 0 Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404706 Share on other sites More sharing options...
btherl Posted December 3, 2007 Share Posted December 3, 2007 Then that's your problem. You must pass the page argument using $_GET in order to retreive it from $_GET. Can you show us how you call your script? Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404708 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 when I did the 360news switch it just shows 360 but it still works... I don't see what your saying Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404732 Share on other sites More sharing options...
therealwesfoster Posted December 3, 2007 Share Posted December 3, 2007 you need to do index.php?page=360news in order to receive $_GET['page']==360news Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404742 Share on other sites More sharing options...
btherl Posted December 3, 2007 Share Posted December 3, 2007 someguy, are you showing us your ENTIRE script or just part of it? What I need to know about how the script is called is, does it look like this: http://www.site.com/script.php?page=360news Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-404771 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 It's only going to the first page of my switch (home), and the 360news one but nothing else Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405398 Share on other sites More sharing options...
SirChick Posted December 3, 2007 Share Posted December 3, 2007 It's only going to the first page of my switch (home), and the 360news one but nothing else your not answering their questions.. which will help them to help you. What is the url when you run the script? Does it have script.php?page=360news if not then it wont work well infact it will work as long as page is correctly spelt across the script (capital letters count too). to get it like that you have to change the url link that was taking the user to that page to have this: <a href="phpscript.php?page=360news">360News</a> This way it will carry the value but change phpscript.php to the name of your php file name.. Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405405 Share on other sites More sharing options...
phpSensei Posted December 3, 2007 Share Posted December 3, 2007 try <?php $page = htmlspecialchars($_GET['page']); switch($page); { case 'home': ('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405406 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 parse error: parse error, unexpected ';', expecting ':' or '{' in /content.php on line 3 gets Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405409 Share on other sites More sharing options...
phpSensei Posted December 3, 2007 Share Posted December 3, 2007 TRY <?php $page = htmlspecialchars($_GET['page']); switch($page); { case 'home': include('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405413 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 same error parse error, unexpected ';', expecting ':' or '{' in /content.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405417 Share on other sites More sharing options...
phpSensei Posted December 3, 2007 Share Posted December 3, 2007 K, what is line 3 edit <?php $page = htmlspecialchars($_GET['page']); switch($page); { to <?php $page = htmlspecialchars($_GET['page']); switch($page) { Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405420 Share on other sites More sharing options...
soycharliente Posted December 3, 2007 Share Posted December 3, 2007 Why do you have a semi colon directly after the switch? Take it out. Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405421 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 ok got rid of error but still doesn't work properly Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405426 Share on other sites More sharing options...
soycharliente Posted December 3, 2007 Share Posted December 3, 2007 Try cleaning it up? Any errors? What's it supposed to do? What's it doing? <?php $page = htmlspecialchars($_GET['page']); switch($page) { case 'home': include('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405427 Share on other sites More sharing options...
phpSensei Posted December 3, 2007 Share Posted December 3, 2007 ok got rid of error but still doesn't work properly Alright, POST the whole script. Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405431 Share on other sites More sharing options...
someguy9 Posted December 3, 2007 Author Share Posted December 3, 2007 I have Content.php <? $page = $_GET['page']; print "page: ".$page; switch($page) { case 'home': include('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); ; break; } ?> and index.php in just a snipplet (TOP) <?php include "./XXXXX.php"; $curdir = getcwd (); chdir('forum'); require_once('forum/global.php'); chdir ($curdir); $page = $_GET ; $XXXX= mysql_query("SELECT * from videos where id = '$_GET[XX]'"); $video = mysql_fetch_array($XXXX); $gamenfo = htmlspecialchars($_GET[info]); if ($vbulletin->userinfo['usergroupid'] == '6' ) { // include lastRSS library include './lastRSS.php'; // create lastRSS object $rss = new lastRSS; // setup transparent cache $rss->items_limit = 6; $rss->cache_dir = './cache'; $rss->cache_time = 120; ?> (then later) <div class="left"> <? include './content.php'; ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405447 Share on other sites More sharing options...
phpSensei Posted December 3, 2007 Share Posted December 3, 2007 You didnt try any of the codes we gave you. Try replacing your content.php with this.. <?php $page = $_GET['page']; print "page: ".$page; switch($page){ case 'home': include('home.php'); break; case 'signup': include('register.php'); break; case 'video': include('video.php'); break; case 'contact': include('contact.php'); break; case 'videosort': include('videosort.php'); break; case 'archive': include('archive.php'); break; case 'search': include('search.php'); break; case 'games': include('game.php'); break; case 'test1': include('test.php'); break; case '360news': include('news.php'); break; case 'addcomment': include('addcomment.php'); break; default: include('home.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/#findComment-405453 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.