Hassanain Posted June 1, 2006 Share Posted June 1, 2006 Hi all, I am a newbie and i am facing a major PROBLEM with my code .. i have done the following code and it was working properly on my machine because i had the global variables thingy set to ON .. now i transfered my work to University machine global variables are set to off .. The technician recommended me to use the $_Get command instead of using it the way i am at the moment The recent code is [code]<a href="?p=register">Register Now</a><? if ($p =="") {?>blah blah blah <? }if ($p =="regtister") {?>blah blah blah <? } ?>[/code]I dont know how i can replace it with $_Get :( Link to comment https://forums.phpfreaks.com/topic/10962-help-with-_get/ Share on other sites More sharing options...
AndyB Posted June 1, 2006 Share Posted June 1, 2006 It's GET, not Get .. and it was sound advice from the technician. Try this:[code]<a href="?p=register">Register Now</a><? if ($_GET['p'] =="") {?>blah blah blah<? }if ($_GET['p'] =="register") {?>blah blah blah<? } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/10962-help-with-_get/#findComment-40934 Share on other sites More sharing options...
Yesideez Posted June 1, 2006 Share Posted June 1, 2006 Try this:[code]<a href="?p=register">Register Now</a><?php $p=$_REQUEST['p'];if (empty($p)) {?> blah blah blah<? }if ($p=="regtister") {?>blah blah blah <? } ?>[/code]Rather than test for "" when checking $p I've opted to use the empty() function. When pulling values off a URL I prefer to use $_REQUEST - just my choice as I prefer to use $_GET with using forms with method=get. You can change it to $_GET if you want. Link to comment https://forums.phpfreaks.com/topic/10962-help-with-_get/#findComment-40935 Share on other sites More sharing options...
SharkBait Posted June 1, 2006 Share Posted June 1, 2006 Take it one set further and use [code]if(isset($_GET['p'])) { if($_GET['p'] == "register") { // Do stuff }}[/code]Check to make sure the url actually has the variable in it else it might not like it depending on how your error reporting is set. Link to comment https://forums.phpfreaks.com/topic/10962-help-with-_get/#findComment-40936 Share on other sites More sharing options...
Yesideez Posted June 1, 2006 Share Posted June 1, 2006 The poor lad is gonna be soooo confused...(ps stick with Andy's - he's a mod ;)) Link to comment https://forums.phpfreaks.com/topic/10962-help-with-_get/#findComment-40938 Share on other sites More sharing options...
QuietWhistler Posted June 1, 2006 Share Posted June 1, 2006 You might want to consider to use a switch..case statement. Like this:[code]switch( $_GET[ 'p' ] ){ case 'register': //do stuff break; case 'logout': //do other stuff break; default: //do default stuff (so if 'p' is empty or anything else that isn't in the statement above)}[/code] Link to comment https://forums.phpfreaks.com/topic/10962-help-with-_get/#findComment-40966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.