Newbie PHP coding problem: header function (maybe, I need someone to check my code)

Posted by Haskella on Stack Overflow See other posts from Stack Overflow or by Haskella
Published on 2010-05-22T12:34:25Z Indexed on 2010/05/22 12:40 UTC
Read the original article Hit count: 265

Filed under:
|

Hi, consider the following PHP code:

<?php
$searchsport = $_REQUEST['sport'];
$sportarray = array(
"Football" => "Fb01",
"Cricket" => "ck32",
"Tennis" => "Tn43",
);
header("Location: ".$sportarray[$searchsport].".html"); //directs user to the corresponding page they searched
if ($searchsport == NULL) {
header("Location: youtypednothing.html"); //directs user to a page I've set up to warn them if they've entered nothing
} else {
header("Location: sportdoesnotexist.html"); //if sport isn't in my root, a warning will appear
}
?>

I think the code comments are self-explanatory, basically when I type Tennis on my form.html it will send data to this php file and process and direct me to Tn43.html which is my tennis page. Unfortunately, it doesn't work and I really want to know why... (I know I've made some huge silly mistake).

PS: Is header the right function to use when doing some redirecting?

© Stack Overflow or respective owner

Related posts about php

Related posts about header