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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度