Jump to content

Archived

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

Hassanain

Help with $_Get

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 :(

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
The poor lad is gonna be soooo confused...

(ps stick with Andy's - he's a mod ;))

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.