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
Share on other sites

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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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