Page 1 of 1

PHP Switch Issues

Posted: Wed Jul 20, 2011 6:28 pm
by 4cpukid
I am trying to have multiple sections of a page using PHP by using two switch commands. So the link to get there is

Code: Select all

?lang=css&code=lightbox
however when I go there all I see is my NOCODE case instead of the content. THe code is below:

Code: Select all

<?php
						$lang=$_GET['lang'];
						if($lang==""){$lang="none";}
						
						switch($lang){
						
						case "none":
						@include('lang/none.php');
						break;
						
						case "html":
						@include('lang/html.php');
						break;
						
						case "css":
						@include('lang/css.php');
						break;
						
						}
					?>
						<hr />
					<?php
						$code=$GET['code'];
						if($code==""){$code="nocode";}
						
						switch($code){
						
						case "nocode":
							echo "ERROR 700: <em>NO SCRIPT SELECTED</em>";
						break;
						
						case "lightbox":
						@include('code/lightbox.php');
						break;
							
						}
					?>
thanks in advance

the URL for all of this is at http://beta.somethinghandy.com/code?lang=css

Re: PHP Switch Issues

Posted: Wed Jul 20, 2011 8:09 pm
by McInfo
$GET is missing an underscore.

During development, your script should start with this:

Code: Select all

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL | E_STRICT);
Avoid using the @ operator. Use it only when you can't prevent an error with predictive logic. Definitely don't use it during development.

Use isset() or array_key_exists() to check if an index is in an array before using it. Be aware that the two behave differently when the element is NULL.