I've read through a lot of answers on this site already, but all of the solutions have never helped this issue. I have code to redirect a page using PHP based on the form data they submit for a survey project. The header should redirect to another page based on the user selection from the drop down list. All of them are stored in the www directory on my localhost WAMP server. The problem is, the page does not redirect to the page I specify in the header redirect, but instead just reloads the current page. I need it to redirect to the pages specified in the headers.
Here is the PHP:
<?php
session_start();
if(isset($_POST['post'])) {
$_SESSION['maintasked'] = $_POST['maintask'];
$_SESSION['dated'] = $_POST['date'];
$_SESSION['named'] = $_POST['name'];
session_write_close();
if(!empty($_POST['name']))
{
switch($_POST['maintask']) {
case "Pre Cabinet":
header('Location: /Tier2PreCabinet.php');
exit;
break;
case "At Cabinet":
header('Location: /Tier2AtCabinet.php');
exit;
break;
case "Post Cabinet":
header('Location: /Tier2PostCabinet.php');
exit;
break;
}
}
}
?>
And here is the HTML:
<!doctype html>
<html>
<head>
<meta charset = "utf-8">
<title>Advanced RV Time Records</title>
</head>
<body>
<h2>Advanced RV Time Capsule</h2>
<!-- This form grabs today's date from the JS run at page load and allows the user to change it if necessary -->
<p>Enter the date of the day the work was done.</p>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="date" id="theDate" value="" name ="date">
<!-- This form has the user select the name they will be working under. Must be completed. -->
<p id ="name" name="named">Enter the name of the worker performing the task. </p>
<select id="workers" name="name">
<option value =null></option>
<option>Brian</option>
<option>Mike G.</option>
<option>Anthony</option>
<option>Tom</option>
<option>Joe</option>
<option>Deury</option>
<option>Chris Puetzfeld</option>
<option>Chris Piercy</option>
<option>Frank</option>
</select>
<!-- This form has the user select the task they will be working on.-->
<p>Enter the main task that the worker will be doing</p>
<select id ="MainTask" name ="maintask">
<option id ="1">Pre Cabinet</option>
<option value ="2">At Cabinet</option>
<option value ="3">Post Cabinet</option>
</select>
<input type ="submit" value="Continue On">
</form>
</body>
</html>