Jump to content


Photo

Help with $_Get


  • Please log in to reply
5 replies to this topic

#1 Hassanain

Hassanain
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 01 June 2006 - 03:02 PM

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

<a href="?p=register">Register Now</a>

<? if ($p =="") {?>

blah blah blah 

<? }

if ($p =="regtister") {?>

blah blah blah 

<? } ?>

I dont know how i can replace it with $_Get :(

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 June 2006 - 03:09 PM

It's GET, not Get .. and it was sound advice from the technician. Try this:
<a href="?p=register">Register Now</a>

<? if ($_GET['p'] =="") {?>

blah blah blah

<? }

if ($_GET['p'] =="register") {?>

blah blah blah

<? } ?>

Legend has it that reading the manual never killed anyone.
My site

#3 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 01 June 2006 - 03:10 PM

Try this:
<a href="?p=register">Register Now</a>
<?php $p=$_REQUEST['p'];
if (empty($p)) {?>
  blah blah blah
<? }
if ($p=="regtister") {?>
blah blah blah 
<? } ?>
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.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 01 June 2006 - 03:12 PM

Take it one set further and use

if(isset($_GET['p'])) {
  if($_GET['p'] == "register") {
    // Do stuff
  }
}

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.

#5 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 01 June 2006 - 03:15 PM

The poor lad is gonna be soooo confused...

(ps stick with Andy's - he's a mod ;))
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#6 QuietWhistler

QuietWhistler
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationThe Netherlands

Posted 01 June 2006 - 05:36 PM

You might want to consider to use a switch..case statement. Like this:

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)
}

Greetings, Shady EL Gewily




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users