Jump to content

Help with $_Get


Hassanain

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.