Newbie PHP coding problem: header function (maybe, I need someone to check my code)
- by Haskella
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?