Page 1 of 1

whats wrong?

Posted: Fri Dec 06, 2002 10:08 pm
by stickman373
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';
}
?>

Posted: Fri Dec 06, 2002 10:51 pm
by qiangxd
now
you have a mistaken like this

Code: Select all

<?php
if ($dl ='pcgame') {
correct
if ($dl =='pcgame') {


?>

Posted: Sat Dec 07, 2002 1:26 pm
by f1nutter
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';
} 
?>

Posted: Sat Dec 07, 2002 8:59 pm
by stickman373
thanks :wink: