steff_dk Posted October 15, 2006 Share Posted October 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
marcus Posted October 15, 2006 Share Posted October 15, 2006 what do you mean?[code]if($frameID == false){$frameID=1;}else if($frameID == value){$frameID=2;};[/code]like that? Quote Link to comment Share on other sites More sharing options...
steff_dk Posted October 15, 2006 Author Share Posted October 15, 2006 Not exactly. The variable is sent to the page by "GET method" e.g. myphppage.php?frameID=1I need to assign a value to frameID if I just access the page like; myphppage.php (with no "?frameID=blabla") Quote Link to comment Share on other sites More sharing options...
marcus Posted October 15, 2006 Share Posted October 15, 2006 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 Quote Link to comment Share on other sites More sharing options...
steff_dk Posted October 15, 2006 Author Share Posted October 15, 2006 [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. Quote Link to comment Share on other sites More sharing options...
Stooney Posted October 15, 2006 Share Posted October 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
steff_dk Posted October 15, 2006 Author Share Posted October 15, 2006 Spot on!It was !isset() I needed ;)Thx a bunch! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.