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
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
Share on other sites

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.