Jump to content

[SOLVED] If a command does not exist - how do i display an error?


raryre23

Recommended Posts

I haven't used PHP a while so I'm a bit stuck here..

 

This is my index page code:

 

<?php
require ("config.php");
include("functions.php");
$ses_username = $_SESSION['ses_username'];
$cmd = isset($_GET['cmd'])?$_GET['cmd']:1;

switch($cmd)
{
case 1:$file="main.php";

			break;
case 2:$file="signup.php";
		  
			break;

}

include("header.php"); ?>


<div align="left"> 
  
        <?php include($file); 
	?>
      
  <br>
</div>
<div align="left"> 
  <?php include("footer.php"); 
   ?>

 

I cut out some of the cases, there's actually about twenty. But what i need to do is check that the command exists and then, if it doesn't, just display my own error message. At the moment, if i change the  address from something like "http://www.mysite.com/index.php?cmd=2" to "http://www.mysite.com/index.php?cmd=25" (cmd=25 doesn't exist) then I get:

 

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/local/php5/lib/php') in .....

 

Any help would be great  :)

 

 

You just need to add a default: to your switch

switch($cmd)
{
case 1:$file="main.php";

			break;
case 2:$file="signup.php";
		  
			break;
        default:
              //not avail
              break;

}

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.