Jump to content

Archived

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

steff_dk

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

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]

Share this post


Link to post
Share on other sites
what do you mean?

[code]
if($frameID == false){
$frameID=1;
}else if($frameID == value){
$frameID=2;
};
[/code]

like that?

Share this post


Link to post
Share on other sites
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")

Share this post


Link to post
Share on other sites
i still dont see what your trying to do

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

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

post the full script

Share this post


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

Share this post


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

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.