Forum Moderators: coopster
I'm trying to have different text included in a div based on a variable in the URL.
For instance, http://www.example.com/?formType=AIR-CAR-HOTEL
would include air-car-hotel.php
and
http://www.example.com/?formType=CAR-HOTEL
would include car-hotel.php
The problem is that only the last statement is being included:
} else {
include('include/air-only.php');
and none of the URL variables are making the include change as I want it to.
Here's the code I have:
<?php
if(isset($_GET['AIR-ONLY'])){
include('include/air-only.php');
}else if(isset($_GET['AIR-CAR'])){
include('include/air-car.php');
}else if(isset($_GET['AIR-CAR-HOTEL'])){
include('include/air-car-hotel.php');
}else if(isset($_GET['AIR-HOTEL'])){
include('include/air-hotel.php');
}else if(isset($_GET['CAR-HOTEL'])){
include('include/car-hotel.php');
} else {
include('include/air-only.php');
}
?>
Can anyone tell me what I'm doing wrong here? I really appreciate it!
[edited by: dreamcatcher at 6:47 am (utc) on June 5, 2008]
[edit reason] use example.com. Thanks. [/edit]
if(!isset($_GET['formType'])) [url=http://www.php.net/exit]exit[/url];
#
switch($_GET['formType']) {
case 'AIR-ONLY':
$page = 'air-only.php';
break;
case 'AIR-CAR':
$page = 'air-car.php';
break;
# etc...
default:
$page = 'air-only.php';
}
include('include/$page');
This uses the switch statement [us2.php.net] here.
I tried that code and it's giving an error.
Warning: include(include/$page) [function.include]: failed to open stream: No such file or directory in /home/#*$!#*$!/public_html/index2.html on line 244
Warning: include() [function.include]: Failed opening 'include/$page' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/#*$!#*$!/public_html/index2.html on line 244
I actually commented out that first line because it leaves a blank page if there's no variable. Instead I want it to use the default air-only.php.
Here's the exact code I have on my page. Do you see any thing wrong?
<?php
#if(!isset($_GET['formType'])) exit;
#
switch($_GET['formType']) {
case 'AIR-ONLY':
$page = 'air-only.php';
break;
case 'AIR-CAR':
$page = 'air-car.php';
break;
case 'AIR-CAR-HOTEL':
$page = 'air-car-hotel.php';
break;
case 'AIR-HOTEL':
$page = 'air-hotel.php';
break;
case 'CAR-HOTEL':
$page = 'car-hotel.php';
break;
default:
$page = 'air-only.php';
}
include('include/$page');
?>
Thanks.
include("include/$page");