簡體   English   中英

php腳本正在工作,現在第二個$ _POST突然不工作

[英]php script was working, now second $_POST suddenly not working

我是php新手,已經搜尋了三天才能找到我的問題。 下面的腳本工作了兩年,現在突然第二個POST命令就再也沒有填充(這是代碼的最后幾行,當我回顯$_POST['input'];什么都沒有。)我看着var_dump$[_$POST]並獲得$formType ,但從未獲得$input

為什么這突然停止工作? 它將轉到下一種形式,但是沒有任何效果,因為這都取決於傳遞的$input

我在UNIX服務器“網絡解決方案”上運行。

任何幫助是極大的贊賞!!

這是代碼(顯然是目錄和數據庫的消毒名稱):

<?php
    session_start();
    if ($_SESSION['auth'] != "yes") {
        header("Location: login.php");
        exit();
    }

    if (isset($_REQUEST['Enter'])) {
        header("Location: http://www.mysite.com/subdirectory/nextform.php");
    } else if (isset($_REQUEST['Delete'])) {
        header("Location: http://www.mysite.com/subdirectory/deleterow.php");
    }
    ########################################
    ####checks what kind of service request######
    #########################################

?>

<form name="form" method="post" action="<?php
echo htmlentities($_SERVER['PHP_SELF']);
?>"> 
<p><legend>Form Type</legend></p>
<p> <basefont size = "4"></p>
<p><label for="formType" required>*Select Type of Form:</label></p>
<p><select name="formType"></p>
<p><option value="">select</option></p>
<p><option value="Garda">Security Officer</option></p>
<p><option value="Surveil">Surveil</option></p>
<p><option value="EmployApp">Employment Application</option></p>
<p></select></p>
<p><input type="submit" name="Submit" value="Submit" /></p>
</form> 
    <?php

    $formType = $_POST['formType'];

    SESSION_register("formType");


    if ($formType == Garda) {

        // Connects to your Database 
        include("introGardaform.php");
        $database = "Gardaform"; // provide your database name 
        $db_table = "GardaINQ"; // leave this as is 

        $db = mysql_connect($hostname, $db_user, $db_password);
        mysql_select_db($database, $db);

        $data = mysql_query("SELECT * FROM GardaINQ") or die(mysql_error());

        // puts the "GardaINQ"database table info into the $info array 
        //$info = mysql_fetch_array( $data ); 

        Print "<table border cellpadding=15>";
        while ($info = mysql_fetch_array($data)) {
            Print "<tr>";
            Print "<th>Inquiry Number:</th> <td>" . $info['Inquiry_num'] . "</td> ";
            Print "<th>Contact Name:</th> <td>" . $info['contactName'] . " </td>";
            Print "<th>Contact Number:</th> <td>" . $info['contactNum'] . " </td></tr>";
        }
        Print "</table>";
    }

    if ($formType == Surveil) {

        // Connects to your Database 
        include("investfm.php");
        $database = "investigateform"; // provide your database name 
        $db_table = "surveil"; // leave this as is 

        $db = mysql_connect($hostname, $db_user, $db_password);
        mysql_select_db($database, $db);

        $data = mysql_query("SELECT * FROM surveil") or die(mysql_error());

        // puts the "surveil"database table info into the $info array 
        //$info = mysql_fetch_array( $data ); 

        Print "<table border cellpadding=15>";
        while ($info = mysql_fetch_array($data)) {
            Print "<tr>";
            Print "<th>Inquiry Number:</th> <td>" . $info['Inquiry_num'] . "</td> ";
            Print "<th>Contact Name:</th> <td>" . $info['contactName'] . " </td>";
            Print "<th>Contact Number:</th> <td>" . $info['contactNum'] . " </td></tr>";
        }
        Print "</table>";
    }

    if ($formType == EmployApp) {

        // Connects to your Database 
        include("introhires.php");
        $database = "hires"; // provide your database name 
        $db_table = "hiresentry"; // leave this as is 

        $db = mysql_connect($hostname, $db_user, $db_password);
        mysql_select_db($database, $db);

        $data = mysql_query("SELECT * FROM hiresentry") or die(mysql_error());

        // puts the "hiresentry"database table info into the $info array 
        //$info = mysql_fetch_array( $data ); 

        Print "<table border cellpadding=15>";
        while ($info = mysql_fetch_array($data)) {
            Print "<tr>";
            Print "<th>First Name:</th> <td>" . $info['firstName'] . " </td>";
            Print "<th>Last Name:</th> <td>" . $info['lastName'] . " </td>";
            Print "<th>Date:</th> <td>" . $info['date'] . " </td></tr>";
        }
        Print "</table>";
    }

?>

<form name="finddata" method="POST" action="<?php
echo htmlentities($_SERVER['PHP_SELF']);
?>"> 
<p> <basefont size = "4"></p>
<p><label for="finddata" required>Enter Inquiry Number for Garda or Surveil, Last name for Employment 

Application:</label></p>
<p><input type = "text" size="20" maxlength="40" required onKeyPress="return noenter()" 

name="input"></p>
<p><input type="hidden" value="<?php
echo $formType;
?>" name="formType"></p>
<p><input type="submit" name="Enter" value="Enter" ></p><br/>
<p><input type="submit" style="font-face: 'Comic Sans MS'; font-size: larger; color: red; background-color: #FFFFC0; border: 3pt ridge lightgrey"   name = "Delete" value="Delete"></p>
</form> 

<?php

    $input = $_POST['input'];
    SESSION_register("input");
    echo $_POST['input'];

?>

您已經使用了SESSION_register("formType"); undefined函數,此函數自PHP 5.3.0起已棄用,而PHP 5.4.0起已刪除。

因此,您可以使用$_SESSION["formType"]=$formType; ,也

需要使用換行符"'來檢查字符串。

if($formType=="Garda"){

if($formType=="EmployApp"){

代替

if($formType==Garda){

if($formType==EmployApp){

您的代碼有很多問題。

  • 您正在將$formtype變量與常量進行比較。 一定是這樣 if($formType=="Garda"){if($formType=="Surveil"){if($formType=="EmployApp"){如所示,雙引號添加到所有if語句中。
  • 您正在使用不建議使用的版本,即session_register

您可以嘗試以下方法:

  1. 從兩個表單中完全刪除action屬性,因為默認情況下它是POST自我。
  2. 將第二個表單的最后一個元素中的font-face css屬性替換為font-family屬性。 但是,這不應成為您面臨的問題的原因。
  3. 由於頁面中有2個表單,並且有2個代碼塊,具體取決於表單發布,因此我假設您的第二個表單發布會在代碼的第一部分中創建問題,因為第一個from的數據將不會從表單中發布。第二種形式的“提交”按鈕。 因此在執行一段代碼之前,您應該確定是否應該執行該段代碼。 一個簡單的多窗體設置應如下所示:
     <form name="form1" method="post">
         <input type="text"/>
         <input type="submit" name="form1-submit" value="Submit Name" />
     </form>

     <!-- form1 specific code -->
     <?php
         if(isset($_POST["form1-submit"]))
         {
             // do your stuff here
         }
     ?>

     <form name="form2" method="post">
         <input type="text"/>
         <input type="submit" name="form2-submit" value="Submit Name" />
     </form>

     <!-- form2 specific code -->
     <?php
         if(isset($_POST["form2-submit"]))
         {
             // do your stuff here
         }
     ?>

     <!-- independent code -->
     <?php
         // do your common code here.
     ?>

如果您可以按照上述方式編寫代碼,則可以自己解決問題。 如果上述情況有所幫助,請告知我們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM