Jump to content


Photo

Replace variable value if no get-variable was passed ...


  • Please log in to reply
6 replies to this topic

#1 steff_dk

steff_dk
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSilkeborg, Denmark

Posted 15 October 2006 - 09:18 PM

Hi all!

First post here  ;)

I have a page that takes a 'GET' var, but what if there wasn't passed any var? How can I set a default value in those cases?

I have tried this with no luck:
$frameID= $_GET['frameID'];
if(!frameID){
$frameID=1;
}


#2 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 15 October 2006 - 09:19 PM

what do you mean?

if($frameID == false){
$frameID=1;
}else if($frameID == value){
$frameID=2;
};

like that?

#3 steff_dk

steff_dk
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSilkeborg, Denmark

Posted 15 October 2006 - 09:29 PM

Not exactly. The variable is sent to the page by "GET method" e.g. myphppage.php?frameID=1

I need to assign a value to frameID if I just access the page like; myphppage.php (with no "?frameID=blabla")

#4 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 15 October 2006 - 09:32 PM

i still dont see what your trying to do

$frameid = $_GET[frameID];
if($frameid == false){
echo "suttin";
}else if($frameid == 1){
echo "suttin else";
};

i still dont see what you're trying to do,

post the full script

#5 steff_dk

steff_dk
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSilkeborg, Denmark

Posted 15 October 2006 - 09:43 PM

$frameID= $_GET['frameID'];
This is the full script so far.

But I can't do a logical test if frameID==false if no variable was passed can I?

If I make a page called myphppage.php that has the following code:
$frameID= $_GET['frameID'];
print("$frameID")
-and access it by the following address: myphppage.php?frameID=TheVariablePassed my browser will show: "TheVariablePassed"
If I access it by typing just myphppage.php my browser will show a blank screen.

I need to default the variable frameID if no variable was passed.



#6 Stooney

Stooney
  • Members
  • PipPipPip
  • Advanced Member
  • 1,093 posts
  • LocationLas Cruces, NM

Posted 15 October 2006 - 09:49 PM

hmmm...i see what your saying maybe something like this...

if(!isset($frameID)) 
{
      header("Location:  http://address.com?frameID=1");
}


or if you have other variable you wanna keep in there:  (assuming var1 and var2 are already set)

if(!isset($frameID))
{
      $url="http://address.com?var1=".$var1."&var2=".var2."&frameID=1";
      header("Location:  $url");
}

im pretty sure that the "header("Location:  $url");"  should work (unsure about variable inside there).  Hope that helped.

Also, just thought of this, if you just need the variable set for the page and not in the address:

if(!isset($frameID))
{
      $frameID=1;
}

<embed src='.wav' autostart='true' loop='false'
width='2' height='0'>
</embed>
i found that ERMMMMM thats called PHP!!!!


#7 steff_dk

steff_dk
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationSilkeborg, Denmark

Posted 15 October 2006 - 10:03 PM

Spot on!

It was !isset() I needed  ;)

Thx a bunch!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users