PHP Switch not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
4cpukid
Forum Newbie
Posts: 4
Joined: Wed Jul 20, 2011 6:27 pm

PHP Switch not working

Post by 4cpukid »

I have this command that in the URL bar if it reads <<<<>>>>/?view=old - it will view old.php but no matter what the case is all i see is MAIN. I pasted the code below Thanks in advance.

Code: Select all

<?php
			
			// =========================DO NOT ALTER ANYTHING BELOW THIS LINE========================
			
			$view = $_GET['view'];
			if ($view=="") { $view = "main"; }
			
			switch($view){
			
			case "main":
			@include('news/main.php');
			break;
			
			case "new":
			$new = file_get_contents('http://cp.cioffitech.com/files/news/new.php');
			echo $new;
			break;
			
			case "old":
			$old = file_get_contents('http://cp.cioffitech.com/files/news/old.php');
			echo $old;
			break;
			
			case "all":
			$all = file_get_contents('http://cp.cioffitech.com/files/news/all.php');
			echo $all;
			break;
			
			}			
		?>

User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP Switch not working

Post by Jonah Bron »

Is that all the code? Is there anything else that could affect it? Try removing the if clause. Are you sure you entered in the URL query string (?view=old) correctly?
kaydeveloper
Forum Newbie
Posts: 2
Joined: Mon Jul 25, 2011 1:42 am

Re: PHP Switch not working

Post by kaydeveloper »

I think the code which you have provided is completely perfect but you need to be sure that are you really passing the view=old in the URL?
4cpukid
Forum Newbie
Posts: 4
Joined: Wed Jul 20, 2011 6:27 pm

Re: PHP Switch not working

Post by 4cpukid »

Heres the page that uses this file:

Code: Select all

<?php
session_start(); // start session cookies (otherwise won't remember login between pages)

require("../includes/config.php");
require("../includes/Database.singleton.php");
require("../includes/Login.singleton.php");

// create initial singleton database connection and connect
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$db->connect();

// create login singleton object
$login = Login::obtain();

// force a user login
$login->hard(2);
?>

<!DOCTYPE html>
<html>
	<head>
		<title>Access CP - Admin - Home</title>
			<style>
				#errorbar {
					background-color: #770000;
					color: #ffffff;
					text-align: center;
					font-size: 9pt;
					margin: auto;
				}
			</style>
		<link rel="stylesheet" href="main.css" type="text/css">
		<script src="http://www.cioffitech.com/ct/c/div.js"></script>
	</head>
	<body>
		<div class="f_container">


<div class="f_header">
<?php require('includes/header.inc.php'); ?>
</div>

<div class="f_menu">
<?php require('includes/menu.inc.php'); ?>
</div>

<div class="f_body">
	<span align="center" id="errorbar">ATTENTION: We are experiancing some issues with our news feed and the THREE NEW CONTROL BUTTONS at thee bottom of the page are not functioning.</span><br /><br />
	<?php
		/* News and Updates of the Control Panel are kept and feed through the CioffiTech Server. DO NOT TOUCH THIS LINE OF CODE! */
		/* @include('../../sd/cp/files/news.php'); */
		/* echo implode(file("http://http://cp.cioffitech.com/files/news.php")); */
		$newsfeed = file_get_contents('http://cp.cioffitech.com/files/news.php');
		echo $newsfeed;
	?>
</div>
<div class="f_footer">
<?php require('includes/footer.inc.php'); ?>
</div>


</div>

	</body>
</html>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP Switch not working

Post by Jonah Bron »

Is it one of the includes? Which one?
4cpukid
Forum Newbie
Posts: 4
Joined: Wed Jul 20, 2011 6:27 pm

Re: PHP Switch not working

Post by 4cpukid »

4cpukid wrote:Heres the page that uses this file:

Code: Select all

<?php
session_start(); // start session cookies (otherwise won't remember login between pages)

require("../includes/config.php");
require("../includes/Database.singleton.php");
require("../includes/Login.singleton.php");

// create initial singleton database connection and connect
$db = Database::obtain(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$db->connect();

// create login singleton object
$login = Login::obtain();

// force a user login
$login->hard(2);
?>

<!DOCTYPE html>
<html>
	<head>
		<title>Access CP - Admin - Home</title>
			<style>
				#errorbar {
					background-color: #770000;
					color: #ffffff;
					text-align: center;
					font-size: 9pt;
					margin: auto;
				}
			</style>
		<link rel="stylesheet" href="main.css" type="text/css">
		<script src="http://www.cioffitech.com/ct/c/div.js"></script>
	</head>
	<body>
		<div class="f_container">


<div class="f_header">
<?php require('includes/header.inc.php'); ?>
</div>

<div class="f_menu">
<?php require('includes/menu.inc.php'); ?>
</div>

<div class="f_body">
	<span align="center" id="errorbar">ATTENTION: We are experiancing some issues with our news feed and the THREE NEW CONTROL BUTTONS at thee bottom of the page are not functioning.</span><br /><br />
	<?php
		/* News and Updates of the Control Panel are kept and feed through the CioffiTech Server. DO NOT TOUCH THIS LINE OF CODE! */
		/* @include('../../sd/cp/files/news.php'); */
		/* echo implode(file("http://http://cp.cioffitech.com/files/news.php")); */
		$newsfeed = file_get_contents('http://cp.cioffitech.com/files/news.php');
		echo $newsfeed;
	?>
</div>
<div class="f_footer">
<?php require('includes/footer.inc.php'); ?>
</div>


</div>

	</body>
</html>
------Sorry about that - Its the '$newsfeed'.--------
Post Reply