Sycohazza Posted September 1, 2011 Share Posted September 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/ Share on other sites More sharing options...
noXstyle Posted September 1, 2011 Share Posted September 1, 2011 Hiya, Are you certain that the 'page' index is passed to the index page? Only way I could reproduce the notification is not to pass the ?page= part to the url. Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264515 Share on other sites More sharing options...
Pikachu2000 Posted September 1, 2011 Share Posted September 1, 2011 Why are you defining a constant 'page' as 'page'? If that was to clear up an "undefined constant" notice, all you would have needed to do was to quote the array index: $_GET['page'] . . . Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264525 Share on other sites More sharing options...
Sycohazza Posted September 1, 2011 Author Share Posted September 1, 2011 if i dont i get another warning Notice: Use of undefined constant page - assumed 'page' in C:\xampp\htdocs\template1\index.php on line 35 with quotes i get Notice: Undefined index: page in C:\xampp\htdocs\template1\index.php on line 35 Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264545 Share on other sites More sharing options...
Pikachu2000 Posted September 1, 2011 Share Posted September 1, 2011 . . . If that was to clear up an "undefined constant" notice, all you would have needed to do was to quote the array index: $_GET['page'] . . . Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264546 Share on other sites More sharing options...
Sycohazza Posted September 1, 2011 Author Share Posted September 1, 2011 sorry, i modded the other post, after i re read what you wrote b4 you reposted Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264547 Share on other sites More sharing options...
Sycohazza Posted September 1, 2011 Author Share Posted September 1, 2011 ok i fixed it my new code is <?php if ($_GET){ switch("$_GET ") { case "news": include "news.php"; break; case "is-it-for-me": include "for_me.php"; break; } } ?> Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264553 Share on other sites More sharing options...
DavidAM Posted September 1, 2011 Share Posted September 1, 2011 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264554 Share on other sites More sharing options...
Sycohazza Posted September 1, 2011 Author Share Posted September 1, 2011 ah isee what you mean, yea i did originally have the quote around page, i am new to learning php and i was quick to reply, the problem with if statement is that it doesnt load a default page, making the home page empty to begin with Quote Link to comment https://forums.phpfreaks.com/topic/246214-undefined-index/#findComment-1264556 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.