cedricganon Posted November 3, 2011 Share Posted November 3, 2011 Hello everyone. I had another account here but it seems to have been wiped from the face of the internets. oh well. I was working on a basic form on a multilanguage website so i need it to properly acknowledge what language it is working with. the link to the page would be like so: index.php?lang=en&sb=1 so the code, as required to read it, is as follows: if(isset($_GET['lang']) == TRUE){ switch($_GET['lang']){ case 'en': case 'it': case 'pl': $validlang = $_GET['lang']; break; default: $validlang = 'en'; break; } } else{ $validlang = 0; } if(isset($_GET['sb']) == TRUE){ if(is_numeric($_GET['sb'] == FALSE)){ $error = 1; } if($error == 1){ header("Location" . $config_basedir); } else{ $validentry = $_GET['sb']; } } if($validlang == 0){ echo "An unknown error has occurred." . mysql_error(); } for whatever reason $validlang always comes out with the value 0. I even set tried setting $validlang = 'en'; before that snippet to at least force it to hold some value but I'm obviously doing something stupid here (isn't that usually the case ) that I can't seem to catch. Can anyone help clear this up for me? I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/250342-not-retrieving-_get-correctly/ Share on other sites More sharing options...
Zane Posted November 3, 2011 Share Posted November 3, 2011 You have your logic wrong.. Your script does the following... - First checks to see whether there is a query string.. - If true, the switch checks each possibility. Inside this switch, you have empty cases with no breaks.. you also have a default case.. - If there isn't a query string, $validlang is set to zero when it should have gone through the switch to get the default case. You need to first check for the querystring... set a flag or error or whatever.. THEN exit out of that if into the switch. Quote Link to comment https://forums.phpfreaks.com/topic/250342-not-retrieving-_get-correctly/#findComment-1284486 Share on other sites More sharing options...
cedricganon Posted November 3, 2011 Author Share Posted November 3, 2011 You need to first check for the querystring... set a flag or error or whatever.. THEN exit out of that if into the switch. wouldnt the isset() function be the one checking for that string or do you mean something else? Quote Link to comment https://forums.phpfreaks.com/topic/250342-not-retrieving-_get-correctly/#findComment-1284489 Share on other sites More sharing options...
Zane Posted November 3, 2011 Share Posted November 3, 2011 What I meant was, that currently, the switch statement only executes if $_GET['lang'] is set... and inside that switch you have the desired default value for cases when $_GET['lang'] doesn't exist. Metaphor time,... imagine you're in a hallway of doors.. You say to yourself, if (and ONLY if) I enter room 35, I will take a dump. Then when you enter room 35, you go to the bathroom and before dropping your load you say, "Well, if I entered room 36 I would have also taken a dump" ... What's the point of saying that since you're already in room 35? That's what you're doing with your isset right now.. You say, well, if there is a lang variable attached, then I will do this with it, but I will also make a case in case there is no lang.. Then directly after that, you do the same thing again.. but instead you assign it a value of zero. Quote Link to comment https://forums.phpfreaks.com/topic/250342-not-retrieving-_get-correctly/#findComment-1284492 Share on other sites More sharing options...
cedricganon Posted November 3, 2011 Author Share Posted November 3, 2011 I gotcha. Yep stupid mistake. Thanks for help! Quote Link to comment https://forums.phpfreaks.com/topic/250342-not-retrieving-_get-correctly/#findComment-1284493 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.