dongzhang7382 2014-05-21 18:02
浏览 23
已采纳

标题重定向到同一页面,而不是指定的页面

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>
  • 写回答

1条回答 默认 最新

  • dongzhanlu0658 2014-05-21 18:06
    关注

    Select boxes pass the value in the value attribute if set, not the text. On your select box, your first option has no value attribute, so the text will be submitted. However on your second and third options, you have a value of 2 and 3 which is what will be submitted. Your php code is looking for the text values, not the number values that will be submitted.

    You can either change id="1" on your first option to value="1" and in your php look for the values 1, 2 or 3. Or you can remove the value from options 2 and 3 and the text should submit.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献