skyagh Posted August 24, 2007 Share Posted August 24, 2007 switch ($_GET['show']) { case "home": $Board->T->pparse('home'); break; case 'contact': $Board->T->pparse('contact'); break; case "portfolio": $Board->T->pparse('portfolio'); break; default: $Board->T->pparse('home'); break; } Notice: Undefined index: show in C:\Program Files\xampp\htdocs\project\index.php on line 62 I have got a notice of the above code when show is equal to null. case NULL: don't works in that particular case. The notice will not show when something like index.php?show=contact is being casted. I tried to use switch(isset($_GET['show'])) as a solution and the notice does not appear anymore but all the case does not work and not even integers. Quote Link to comment https://forums.phpfreaks.com/topic/66496-solved-need-help-on-switch/ Share on other sites More sharing options...
trq Posted August 24, 2007 Share Posted August 24, 2007 <?php if (isset($_GET['show'])) { switch ($_GET['show']) { case "home": $Board->T->pparse('home'); break; case 'contact': $Board->T->pparse('contact'); break; case "portfolio": $Board->T->pparse('portfolio'); break; default: $Board->T->pparse('home'); break; } else { $Board->T->pparse('home'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66496-solved-need-help-on-switch/#findComment-332963 Share on other sites More sharing options...
radalin Posted August 24, 2007 Share Posted August 24, 2007 That notice is shown because of your error_reporting() check the manaul for it's values. That's not an error. So it will not cause any problem, it will just show an annoying notice message at top. you may try to use null (lowercase) which might work. Quote Link to comment https://forums.phpfreaks.com/topic/66496-solved-need-help-on-switch/#findComment-332965 Share on other sites More sharing options...
wildteen88 Posted August 24, 2007 Share Posted August 24, 2007 Notice: Undefined index: show in C:\Program Files\xampp\htdocs\project\index.php on line 62 I have got a notice of the above code when show is equal to null. case NULL: don't works in that particular case. The notice will not show when something like index.php?show=contact is being casted. I tried to use switch(isset($_GET['show'])) as a solution and the notice does not appear anymore but all the case does not work and not even integers. When PHP shows a notice: undefined index. It means the that that the index (the index is defined within the [] brackets) you have defined does not exist. What you should do is check if it exists first before using the index. To check whether it is exists refer to thorpe's code. Always check to see if _GET, _POST and _COOKIE variables exists first before using them. Quote Link to comment https://forums.phpfreaks.com/topic/66496-solved-need-help-on-switch/#findComment-333234 Share on other sites More sharing options...
skyagh Posted August 25, 2007 Author Share Posted August 25, 2007 Thanks wildteen for the explanation. Clearly understood. & Thanks thorpe for the coding help. Quote Link to comment https://forums.phpfreaks.com/topic/66496-solved-need-help-on-switch/#findComment-333718 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.