stobbo Posted October 29, 2006 Share Posted October 29, 2006 Hello.I am fairly new to PHP, and am struggling over a error. Any help would be kindly appriciated.Error:[code]Notice: Undefined index: id in c:\home\********\public_html\index.php on line 3[/code]Code[code]<?php include("/home/********/public_html/modules/template-top.php");$page= $_GET['id'];if(file_exists("/home/********/public_html/content/".$page.".php")){include("/home/********/public_html/content/".$page.".php");}else{include("/home/********/public_html/modules/news.php");}include("/home/********/public_html/modules/template-bottom.php");?>[/code]If you can help, I would be most pleased.Thanks, Stobbo. Link to comment https://forums.phpfreaks.com/topic/25525-help-with-error/ Share on other sites More sharing options...
trq Posted October 29, 2006 Share Posted October 29, 2006 This will happen when $_GET['id'] hasn't been defined. Try...[code=php:0]<?php include("/home/********/public_html/modules/template-top.php");if(isset($_GET['id']) && file_exists("/home/********/public_html/content/".$_GET['id'].".php")){include("/home/********/public_html/content/".$_GET['id'].".php");}else{include("/home/********/public_html/modules/news.php");}include("/home/********/public_html/modules/template-bottom.php");?>[/code] Link to comment https://forums.phpfreaks.com/topic/25525-help-with-error/#findComment-116480 Share on other sites More sharing options...
Destruction Posted October 29, 2006 Share Posted October 29, 2006 It means that $_GET['id'] isn't setIf someone goes to pagename.php there is no $_GET['id'] as averse to pagename.php?id=1 in which case it is 1.You need to check if it exists first of all...[code]<?php$page = isset($_GET['id']) ? $_GET['id'] : defaultvalue;?>[/code]This will set it to $_GET['id'] if it exists or to a defaultvalue (you'll need to set that) if it doesn't. Also, make sure you're checking the contents of $_GET['id'] before using it, otherwise a user could potentially request any file.HTHDest Link to comment https://forums.phpfreaks.com/topic/25525-help-with-error/#findComment-116481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.