douxiza9868 2017-06-03 11:46
浏览 158

POST不能在我的电脑上运行

Im trying to use Post to read something from my form, but even a simple Example from https://www.w3schools.com/php/php_forms.asp doesn't work. My own code is this:

<form id="eingabe" method="post" action="../php/suche.php">
    <input id="suche" name="suche" type="text" size="50px" placeholder="Suche">
    <input type="submit" value="Submit">
</form>

suche.php

 $rows = array();
   if (isset($_POST['suche'])) {
       $suche = $_POST['suche'];
       $sql= "SELECT * FROM Buch WHERE  titel LIKE '%" . $suche . "%' OR autor LIKE '%" . $suche  ."%' OR isbn LIKE '%" . $suche  ."%' OR genre LIKE '%" . $suche  ."%'";
       $result=$conn->query($sql);
       if ($result->num_rows > 0) {
          while ($row=$result->fetch_assoc()) {
              $titel = $row['titel'];
              $autor = $row['autor'];
              $isbn = $row['isbn'];
              $genre = $row['genre'];
              $preis = $row['preis'];
              $bild = $row['image'];
              $beschreibung = $row['beschreibung'];
              $rows[] = $row;
          }
      }
  }

the var_dump($_POST) is always array(0) { } but in the var_dump($GLOBALS), i can find the word i sending:

array(6) { ["HTTP_RAW_POST_DATA"]=> string(10) "suche=test" ["_GET"]=> array(0) { } ["_POST"]=> array(0) { }...

Question is:

I am using php7.1, but already tried older versions. If i change to GET it works, but i really need to use POST. I also checked my php.ini but POST is activated and has 128MB for ussage. Does anyone have an idea why Post doesnt work for me?

PS: A friend of mine is using the exact same code and it works for him perfectly, so its not the code

  • 写回答

1条回答 默认 最新

  • doudu5498 2017-06-03 12:06
    关注

    You can write your code like this -

     $rows = array();
     if($_SERVER["REQUEST_METHOD"] == "POST"){
       $suche = $_POST['suche'];
       $sql= "SELECT * FROM Buch WHERE  titel LIKE '%" . $suche . "%' OR autor LIKE '%" . $suche  ."%' OR isbn LIKE '%" . $suche  ."%' OR genre LIKE '%" . $suche  ."%'";
       $result=$conn->query($sql);
       if ($result->num_rows > 0) {
          while ($row=$result->fetch_assoc()) {
              $titel = $row['titel'];
              $autor = $row['autor'];
              $isbn = $row['isbn'];
              $genre = $row['genre'];
              $preis = $row['preis'];
              $bild = $row['image'];
              $beschreibung = $row['beschreibung'];
              $rows[] = $row;
          }
          echo "<pre>";
          print_r($rows);
      }
     }else{
       echo "POST method not working";
     }
    

    Here if your POST method will not work then you will get an message "POST method not working" and if your POST method is working then you will get your data using print_r() function.

    Note - This code is only for the testing purpose, Please modify it as per your need.

    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条