raryre23 Posted February 9, 2009 Share Posted February 9, 2009 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 Link to comment https://forums.phpfreaks.com/topic/144481-solved-if-a-command-does-not-exist-how-do-i-display-an-error/ Share on other sites More sharing options...
unkwntech Posted February 9, 2009 Share Posted February 9, 2009 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; } Link to comment https://forums.phpfreaks.com/topic/144481-solved-if-a-command-does-not-exist-how-do-i-display-an-error/#findComment-758118 Share on other sites More sharing options...
raryre23 Posted February 9, 2009 Author Share Posted February 9, 2009 It's working! Thank you! Link to comment https://forums.phpfreaks.com/topic/144481-solved-if-a-command-does-not-exist-how-do-i-display-an-error/#findComment-758124 Share on other sites More sharing options...
unkwntech Posted February 9, 2009 Share Posted February 9, 2009 No problem! Link to comment https://forums.phpfreaks.com/topic/144481-solved-if-a-command-does-not-exist-how-do-i-display-an-error/#findComment-758125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.