微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我无法使用 POST 方法获取标题?

如何解决为什么我无法使用 POST 方法获取标题?

所以我试图通过在第一个 PHP 文件中使用 $_GET['title'] 从 URL 获取标题,但我无法在第二个文件获取文件

网址:

https://easy2book.000webhostapp.com/neworder.php?bookid=101&title=SENIOR%20secondary%20geography%20fieldwork%20and%20assessment%20practice%202021.%20For%20HKDSE%202021%20/%20Ip%20Kim%20Wai%20...%20[et%20al.]

一个文件

<?PHP
  include_once 'header.PHP';
    $id2 = MysqLi_real_escape_string($conn,$_GET['bookid']);
    $title2 = MysqLi_real_escape_string($conn,$_GET['title']);
?>

<section class="neworder-form">
  <h2>Order</h2>
  <div class="neworder-form-form">
    <form action="neworder.inc.PHP" method="post">
      <table>
            <tr>
              <td>Book ID:</td>
              <td>
                 <input type="text" disabled="disabled" name="bookid2" value="<?= $id2 ?>">
              </td>
            </tr>
           <tr>
              <td>Book Title: </td>
              <td>
                 <input type="text" disabled="disabled" name="title2" value="<?= $title2 ?>">
              </td>
           </tr>
           <tr>
               <td>Username: </td>
               <td>
                  <input type="text" name="uid2" placeholder="Username...">
               </td>
            </tr>
            <tr>
               <td>Comfirmed Book ID: </td>
               <td>
                  <input type="text" name="id2" placeholder="Please enter the Book ID....">
               </td>
            </tr>
        </table>
      <button type="submit" name="submit2">Order</button>
    </form>
  </div>
  <?PHP
    // Error messages
    if (isset($_GET["error"])) {
      if ($_GET["error"] == "emptyinput2") {
        echo "<p>Fill in all fields!</p>";
      }
      else if ($_GET["error"] == "usernaMetaken2") {
        echo "<p>Username already taken!</p>";
      }
    }
  ?>
</section>

第二个文件

<?PHP

if (isset($_POST["submit2"])) {

  // First we get the form data from the URL
  $uid2 = $_POST["uid2"];
  $id2 = $_POST["id2"];
  $title2 = $_POST["title2"];

  // Then we run a bunch of error handlers to catch any user mistakes we can (you can add more than I did)
  // These functions can be found in functions.inc.PHP

  require_once "dbh.inc.PHP";
  require_once 'functions2.inc.PHP';

  // Left inputs empty
  // We set the functions "!== false" since "=== true" has a risk of giving us the wrong outcome
  if (emptyInputOrder2($uid2,$id2) !== false) {
    header("location: ../neworder.PHP?error=emptyinput&bookid=$id2&title=$title2");
        exit();
  }
    
  // Is the username exists
  if (uidExists2($conn,$uid2) !== true) {
    header("location: ../neworder.PHP?error=undefineuser");
        exit();
  }

  // If we get to here,it means there are no user errors

  // Now we insert the user into the database
    createuser($conn,$uid2,$id2);

} else {
    header("location: ../neworder.PHP");
    exit();
}

解决方法

  • 输入字段已禁用,禁用的输入不会发布。
  • 替换 $title2 = $_POST[""]; $title2 = $_POST["title2"];

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。