Jump to content

Undefined index


Sycohazza

Recommended Posts


Hi ive been having an issue with this for a long time and i never found a fix from pure google so i have come to ask other human beings :)

 

heres my code:

 

<a href="index.php?page=news">News</a>

 

<?php
	define ('page', 'page');

	switch($_GET

)
	{


  			case "news":
    			 include "news.php"; break;

  			case "is-it-for-me":
     			include "for_me.php"; break;

	}
?>

 

This is what shows up when first entering index.php

 

Notice: Undefined index: page in C:\xampp\htdocs\template1\index.php on line 35

 

Thanks in advance,

Sycohazza

 

Link to comment
https://forums.phpfreaks.com/topic/246214-undefined-index/
Share on other sites

In every configuration I have ever used, $_GET is always defined, so your IF statement will always be true. You need to test for a specific index in the $_GET array. I usually use isset:

 

if (isset($_GET['page'])){

/* NOTE: The double quotes around the entire $_GET[] expression are not needed;
	however, single (or double) quotes are needed around the index	*/
switch($_GET['page']) {  
	case "news":
		include "news.php"; break;

	case "is-it-for-me":
		include "for_me.php"; break;
	}
}

Link to comment
https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264554
Share on other sites

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.