|
-
Jul 31st, 2004, 01:37 AM
#1
Thread Starter
Lively Member
[resolved] If querystring exists?
Hello all.
Code:
<?php
switch ($_GET['lang']) {
case "es":
$txtGreeting = array("buenas dias");
break;
case "fr":
$txtGreeting = array("bon jour");
break;
default:
$txtGreeting = array("good day");
}
?>
The above code works just fine when I click on a link such as:
Code:
<a href="index.php?lang=fr">French</a>
But if I click a link without the querystring (?lang=fr), I receive a nasty error message:
"Undefined index: lang"
Could anyone explain to me how to determine if a querystring exists BEFORE performing the switch statement?
Or, if possible, how I could switch to default if the querystring is absent?
Many thanks.
Last edited by solitario; May 27th, 2005 at 02:55 PM.
-
Jul 31st, 2004, 06:24 AM
#2
Frenzied Member
put all that in an IF like this:
PHP Code:
if (isset($_GET['lang'))
{
}
That should check if the variable has been set at all. Find out more about the funciton here.
Have I helped you? Please Rate my posts. 
-
Aug 1st, 2004, 03:29 AM
#3
Thread Starter
Lively Member
Works perfectly. Thanks, Acidic!
-
Aug 1st, 2004, 01:56 PM
#4
Stuck in the 80s
It's actually not an error but a notice. There is a way you can setup the php.ini to shut off notices. I have this on my remote server, but on my test server I have it turned on, just because it helps practice better coding habits.
If you're interested in finding knowing how to shut it off, let us know. I would encourage leaving it on, but I just thought I'd let you know there's the option.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|