spookztar Posted July 29, 2007 Share Posted July 29, 2007 Hi guys, I'm having a problem with $_GET coming up empty. I tried searching, but couldn't get to anything with the criteria I used. I have a menu: <a href="<?php echo $_SERVER['PHP_SELF'] ?>?sectionid=1">Product Handling</a><br /> <a href="<?php echo $_SERVER['PHP_SELF'] ?>?sectionid=2">Misc. Parameters</a><br /> <a href="<?php echo $_SERVER['PHP_SELF'] ?>?sectionid=3">Statistics</a><br /> <a href="<?php echo $_SERVER['PHP_SELF'] ?>?sectionid=4">Look 'n' Feel</a> - and when a link is clicked I want the appropriate section of the index.php file to display to the user only using the one file. But when I try to pick up the value with: $sectionid = $_GET['sectionid']; I just get: Notice: Undefined index: sectionid in /home/arioch/public_html/musiccenter.php on line 195 What do I need to do pick up the variable in the URL, so I can use it to load the correct section of the file to the user, using only the one page? Bye, Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/ Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 check that you're setting $sectionid before you're calling it. Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310352 Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 It looks to me like your error reporting is set very, very strictly.... Try doing: $sectionid = (isset($_GET['sectionid']) && is_numeric($_GET['sectionid'])) ? $_GET['sectionid'] : 1; isset doesn't flag an error if you try to check a non existant variable (or key) with it. This will just check if it's set and numeric, and if it is, it will assign it to $sectionid, but if it's empty, it'll assign the default value of 1 to it. Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310356 Share on other sites More sharing options...
spookztar Posted July 29, 2007 Author Share Posted July 29, 2007 It must be empty then, because when echoed, it produces "1" and the other links, nothing at all. And yes, error reporting is strict. I'm a newbie and need to know when something potentially bad is up. Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310366 Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 are you sure $sectionid is being set before you're calling it? and that the spelling (CAPS/no caps etc) is correct? Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310367 Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 you missing the semi colon on the end of the echos Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310368 Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 yeah I saw that too, but didn't think it'd matter on just echoing one variable.. In fact I'm sure I've echoed variables like that before no problem... I may be wrong though Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310370 Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 no it does matter semicolons are used for the compiling purposes. It is what tells the complier hey this is the end of this echo or the end of a variable otherwise what it is doing is its using the question marks as a crude if statement i think or classes, just use proper punctuation Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310375 Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 try this <?php $links[1] = "Product Handling"; $links[2] = "Misc. Paramenters"; $links[3] = "Statistics"; $links[4] = "Look \'n\' Feel"; foreach ($links as $key => $value){ echo "<a href=\"".$_SERVER['self']."?sectionid=".$key."\">".$value."</a>"; } ?> //Page 2 <?php if(ISSET($_GET['sectionid'])){$pageid = $_GET['sectionid'];} ?> then you can add more by appending this array Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310379 Share on other sites More sharing options...
spookztar Posted July 29, 2007 Author Share Posted July 29, 2007 "are you sure $sectionid is being set before you're calling it?" Isn't that the whole point of: sectionid = $_GET['sectionid'];? I'm not in doubt as to whether it's set or not, but why it isn't. I included the semicolons, didn't do a thing. Strict error reporting obviously didn't care either... Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310380 Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 what's your php version I doubt you on 3, but if you are its $_HTTP_GET i believe Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310387 Share on other sites More sharing options...
spookztar Posted July 29, 2007 Author Share Posted July 29, 2007 Thanx for your suggestion cooldude832, but it just gave me "undefined index..." on all four. Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310388 Share on other sites More sharing options...
spookztar Posted July 29, 2007 Author Share Posted July 29, 2007 The version is: PHP Version 4.4.6-2+b1 Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310391 Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 ??? that makes no sense at all Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310392 Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 When set very strictly, the PHP error handling will flag warnings when you try to use not-set variables.... <?php $link = array(); $links[] = "Product Handling"; $links[] = "Misc. Paramenters"; $links[] = "Statistics"; $links[] = "Look \'n\' Feel"; foreach ($links as $key => $value){ echo "<a href=\"page2.php?sectionid=".$key."\">".$value."</a>"; } ?> Then page2: <?php $sectionid = (isset($_GET['sectionid'])) ? $_GET['sectionid'] : 0; echo $sectionid; ?> Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310403 Share on other sites More sharing options...
spookztar Posted July 29, 2007 Author Share Posted July 29, 2007 That works Corbin, but why can't I grab/set the "$sectionid" from the URL and use it to load the proper section of the file when returning to the file itself through the use of PHP_SELF? ??? It just seems so basic... Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310413 Share on other sites More sharing options...
spookztar Posted July 30, 2007 Author Share Posted July 30, 2007 No suggestions as to how I can accomplish the desired result - or at least why I can't use $_GET with PHP_SELF? Could it have something to do with the preceeding use of nested IF/ELSE'S to sanitize an verify log-in details? Link to comment https://forums.phpfreaks.com/topic/62363-using-get-to-load-sections/#findComment-310722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.