PHP,提交后数据未再次加载

时间:2015-11-24 14:47:01

标签: php mysql forms post drop-down-menu

在用户提交表单后,我很难将数据添加回表单中的下拉列表。我想再次显示所选数据。

这是表单下拉列表,如果它有值,我希望它在加载此表单时显示所选数据,但事实并非如此。这是代码:

 <div class="form-group">
            <label class="col-sm-3 control-label">Node</label>
              <div class="col-sm-6">
              <select name="node" id="node" class="form-control m-b" onchange="GetId()" data-required="true">
              <option></option>
              <?php

                $qNode = "SELECT  
                          a.node as selectedNode,
                          a.port as selectedPort,
                          b.node as Nodedata,
                          c.port_no as Portdata
                          FROM configuration a, node b, node_port c
                          WHERE b.id = a.node AND c.id = a.port AND a.id = '$requestID'";

                $rNode = $connection->query($qNode);

                foreach($rNode as $node){
                $nodeid = $node['id'];
                $nodeName = $node['node'];

                echo "<option value=\"$nodeid\" selected=\"selected\">$nodeName</option>";
                }
                echo "<optgroup></optgroup>";

                $qNode = "SELECT id,node FROM node WHERE `status` = 1";

                $rNode = $connection->query($qNode);

                foreach($rNode as $node){
                $nodeid = $node['id'];
                $nodeName = $node['node'];

                echo "<option value=\"$nodeid\">$nodeName</option>";
                }
              ?>
              </select>
          </div>
        </div>

以下是此表单的执行者

 <?php
include("dbconnection.php");
session_start();
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$requesterID = $_SESSION['id'];
print_r($_POST);
$node = $_POST['node'];
$connectionType = $_POST['connectionType'];
$timeSlot = $_POST['timeSlot'];
$dslUnifiNo = $_POST['dslUnifiNo'];
$remarksConfig = $_POST['remarksConfig'];
$portNo = $_POST['portNo'];
$e1circuitNo = $_POST['e1circuitNo'];
$changedDate = $_POST['changedDate'];
$dslUnifiIp = $_POST['dslUnifiIp'];
$requestID = $_POST['requestID'];
$submit = $_POST['Submit'];

if ($submit == "Submit"){
    $status = 1;
}else{
    $status = 2;
}


if(ISSET($_POST['isUpdate'])){
    $qinsert = "UPDATE configuration SET
            node = '$node',
            connection_type = '$connectionType',
            time_slot = '$timeSlot',
            dsl_username = '$dslUnifiNo',
            remarks = '$remarksConfig',
            port = '$portNo',
            e1_curcuit_no = '$e1circuitNo',
            changed_date = '$changedDate',
            dsl_ip = '$dslUnifiIp',
            status = '$status'
            WHERE request_id = '$requestID'";
}else
{
    $qinsert = "REPLACE INTO configuration SET
            node = '$node',
            connection_type = '$connectionType',
            time_slot = '$timeSlot',
            dsl_username = '$dslUnifiNo',
            remarks = '$remarksConfig',
            port = '$portNo',
            e1_curcuit_no = '$e1circuitNo',
            changed_date = '$changedDate',
            dsl_ip = '$dslUnifiIp',
            status = '$status'
            request_id = '$requestID'";

            $requestID = $connection->lastInsertId();

}
$rinsert = $connection->query($qinsert);


            if($status == 1){
                $action = "lineApplication.php";
                $dateCreated = date("Y-m-d H:i:s");
                $userTypeID = 5;

                $qinsertLmu = "INSERT INTO notifications SET
                                user_id = '$requesterID',
                                action = '$action',
                                item_id = '$requestID',
                                created_at = '$dateCreated',
                                receive_user_type_id = '$userTypeID'";
                                echo $qinsertLmu;
                $rinsertLmu = $connection->query($qinsertLmu);
            }

header("location:configuration.php?id=$requestID");

所以问题在于,当用户提交整个表单时,数据会成功转到mysql,但是当我再次重定向到此表单时,下拉列表的字段不会显示由用户。

帮助:)

0 个答案:

没有答案