Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/66496-solved-need-help-on-switch/
Share on other sites

<?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');
}

?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.