Jump to content

[SOLVED] need help on switch


skyagh

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.

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.