PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
stickman373
Forum Commoner
Posts: 30 Joined: Mon Jul 22, 2002 10:26 am
Post
by stickman373 » Fri Dec 06, 2002 10:08 pm
whats wrong with the below code? it works fine if $dl='pcgame' but none of the other ones work?
Code: Select all
<?php
$dl = $_GET[dl]
if ($dl ='pcgame') {
header("Location: /pcgame.php");
}elseif($dl='movie'){
header("Location: /pcgame.php");
}elseif($dl='console'){
header("Location: /console.php");
}elseif($dl='albums'){
header("Location: /album.php");
}elseif($dl='applications'){
header("Location: /application.php");
}elseif($dl='ebook'){
header("Location: /ebook.php");
}elseif($dl='adult'){
header("Location: /adult.php");
}else{
echo 'not a valid input';
}
?>
qiangxd
Forum Newbie
Posts: 8 Joined: Thu Dec 05, 2002 6:00 pm
Post
by qiangxd » Fri Dec 06, 2002 10:51 pm
now
you have a mistaken like this
Code: Select all
<?php
if ($dl ='pcgame') {
correct
if ($dl =='pcgame') {
?>
f1nutter
Forum Contributor
Posts: 125 Joined: Wed Jun 05, 2002 12:08 pm
Location: London
Post
by f1nutter » Sat Dec 07, 2002 1:26 pm
qiangxd is right, you need double equals if you use if statements. You can make things a bit quicker using switch. Also, Location usually needs a complete URL. Some clients will accept relative URLs, but if you move your code, it might suddenly stop working.
Code: Select all
<?php
$dl = $_GET[dl]
switch($dl)
{
case 'pcgame':
header("Location: " .$SERVER_NAME. "/pcgame.php");
break;
case 'movie':
header("Location: " .$SERVER_NAME. "/movie.php");
break;
case 'console':
header("Location: " .$SERVER_NAME. "/console.php");
break;
case 'albums':
header("Location: " .$SERVER_NAME. "/album.php");
break;
case 'applications':
header("Location: " .$SERVER_NAME. "/application.php");
break;
case 'ebook':
header("Location: " .$SERVER_NAME. "/ebook.php");
break;
case 'adult':
header("Location: " .$SERVER_NAME. "/adult.php");
break;
default:
echo 'not a valid input';
}
?>