无法从 php 中的表单读取输入

Unable to read input from a form in php

我无法从 wamp 服务器上 php 运行 中的表单读取输入数据。 以下是代码:

    <?php
    // define variables and set to empty values
    $doctype = $docnbr = $entrydt = $incserno = $incsernodt = $recdfr = $sub = "";

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $doctype = test_input($_POST["doctype"]);   
    $docnbr = test_input($_POST["docnbr"]);
    $entrydt = test_input($_POST["entrydt"]);
    $incserno = test_input($_POST["incserno"]);
    $incsernodt = test_input($_POST["incsernodt"]);
    $recdfr = test_input($_POST["recdfr"]);
    $sub = test_input($_POST["sub"]);
    }

   function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
   }
   ?>

    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" style="margin-bottom:10px; margin-left:10px; margin-right:10px; margin-top:10px">
    <div class="form-group row" style="width:75%">
    <label for="documenttype" class="col-xs-2 col-form-label">Type of Document</label>
    <div class="col-xs-10">
    <select class="form-control" id="documenttype" name="doctype">
    <option selected="selected">Select</option>
    <option>File</option>
    <option>Letter</option>
    </select>
    </div>
    </div>

    <div class="form-group row" style="width:75%">
    <label for="documentnumber" class="col-xs-2 col-form-label">Document Number</label>
    <div class="col-xs-10">
    <input class="form-control" type="text" id="docnumber" name="docnbr" placeholder="<?php echo $max_docno; ?>" readonly>
    </div>
    </div>

    <div class="form-group row" style="width:75%">
    <label for="documententrydate" class="col-xs-2 col-form-label">Entry Date</label> 
    <div class="col-xs-10">   
    <input class="form-control" type='date' id="entrydate" name="entrydt" />
    </div>  
    </div>

    <div class="form-group row" style="width:75%">
    <label for="incomingserno" class="col-xs-2 col-form-label">Incoming Serial Number</label>
    <div class="col-xs-4">
    <input class="form-control" type="text" id="incomingserno" name="incserno">
    </div>
    <label for="indated" class="col-xs-1 col-form-label">Dated</label>
    <div class="col-xs-5">
    <input class="form-control" type="date" id="incomingsernodt" name="incsernodt">
    </div>
    </div>

   <div class="form-group row" style="width:75%">
   <label for="recdfrom" class="col-xs-2 col-form-label">Received From</label>
   <div class="col-xs-10">
   <input class="form-control" type="text" id="recdfrom" name="recdfr">
   </div>
   </div>

   <div class="form-group row" style="width:75%">
   <label for="subject" class="col-xs-2 col-form-label">Subject</label>
   <div class="col-xs-10">
   <textarea class="form-control" id="subject" name="sub"></textarea>
   </div>
   </div>

   <center>
   <input type="submit" name="submit" value="Submit">
   <input type="reset" value="Reset">
   </center>
   </form>

已将 <form menthod="post" 更改为 <form method="post"

变量中没有捕获任何内容: $doctype$docnbr$entrydt、$incserno,$incsernodt,$recdfr,$sub. I have also tried usingisset()`函数来捕获提交按钮的状态而不是检查请求方法但无济于事,我无法从 wamp 服务器上的 php 表单捕获表单数据。

您必须从 menthod to method 并打印您的变量以查看它。

<?php
        // define variables and set to empty values
        $doctype = $docnbr = $entrydt = $incserno = $incsernodt = $recdfr = $sub = "";

        if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $doctype = test_input($_POST["doctype"]);   
        $docnbr = test_input($_POST["docnbr"]);
        $entrydt = test_input($_POST["entrydt"]);
        $incserno = test_input($_POST["incserno"]);
        $incsernodt = test_input($_POST["incsernodt"]);
        $recdfr = test_input($_POST["recdfr"]);
        $sub = test_input($_POST["sub"]);
        echo " $doctype $docnbr $entrydt $incserno $incsernodt $recdfr $sub";

        }

       function test_input($data) {
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
       }
       ?>

        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" style="margin-bottom:10px; margin-left:10px; margin-right:10px; margin-top:10px">
        <div class="form-group row" style="width:75%">
        <label for="documenttype" class="col-xs-2 col-form-label">Type of Document</label>
        <div class="col-xs-10">
        <select class="form-control" id="documenttype" name="doctype">
        <option selected="selected">Select</option>
        <option>File</option>
        <option>Letter</option>
        </select>
        </div>
        </div>

        <div class="form-group row" style="width:75%">
        <label for="documentnumber" class="col-xs-2 col-form-label">Document Number</label>
        <div class="col-xs-10">
        <input class="form-control" type="text" id="docnumber" name="docnbr" placeholder="<?php echo $max_docno; ?>" readonly>
        </div>
        </div>

        <div class="form-group row" style="width:75%">
        <label for="documententrydate" class="col-xs-2 col-form-label">Entry Date</label> 
        <div class="col-xs-10">   
        <input class="form-control" type='date' id="entrydate" name="entrydt" />
        </div>  
        </div>

        <div class="form-group row" style="width:75%">
        <label for="incomingserno" class="col-xs-2 col-form-label">Incoming Serial Number</label>
        <div class="col-xs-4">
        <input class="form-control" type="text" id="incomingserno" name="incserno">
        </div>
        <label for="indated" class="col-xs-1 col-form-label">Dated</label>
        <div class="col-xs-5">
        <input class="form-control" type="date" id="incomingsernodt" name="incsernodt">
        </div>
        </div>

       <div class="form-group row" style="width:75%">
       <label for="recdfrom" class="col-xs-2 col-form-label">Received From</label>
       <div class="col-xs-10">
       <input class="form-control" type="text" id="recdfrom" name="recdfr">
       </div>
       </div>

       <div class="form-group row" style="width:75%">
       <label for="subject" class="col-xs-2 col-form-label">Subject</label>
       <div class="col-xs-10">
       <textarea class="form-control" id="subject" name="sub"></textarea>
       </div>
       </div>

       <center>
       <input type="submit" name="submit" value="Submit">
       <input type="reset" value="Reset">
       </center>
       </form>