Jump to content

[SOLVED] PHP Switch just not working


someguy9

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/79905-solved-php-switch-just-not-working/
Share on other sites

<?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  :-\

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..

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');
  
   }
?>

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');
  
   }
?>

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');
}
?>


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>

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');

   }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.