Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/250342-not-retrieving-_get-correctly/
Share on other sites

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.

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.

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.