Jump to content

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


steff_dk

Recommended Posts

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:
[code]$frameID= $_GET['frameID'];
if(!frameID){
$frameID=1;
}[/code]
Link to comment
Share on other sites

[code]$frameID= $_GET['frameID'];[/code]
This [i]is[/i] 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:
[code]
$frameID= $_GET['frameID'];
print("$frameID")
[/code]
-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.

Link to comment
Share on other sites

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

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


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

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

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:

[code]
if(!isset($frameID))
{
      $frameID=1;
}
[/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.