我的搜索框代码似乎不起作用

时间:2017-05-23 20:08:41

标签: php

我正在尝试为我的项目创建一个搜索框。它的工作是获取输入,查找名称,如果找到,则回显它。它不起作用。我已经完成了大量的教程,他们大多数都和我一样。我检查了我的错误日志,似乎查询有问题。欢迎帮助。

    <div class="subjectBox" style="margin-bottom: 5px;">Patients:</div>

  <?php

    include 'database.php';

    $search = $_POST['search'];

    if(isset($_POST['submit'])){
        if($search === ''){
          $message = "<div style='margin-bottom: 55px;' class='titleBox'>Please fill in all values.</div>";
        } elseif (!empty($search)) {
            $search = strtoupper($search);
            $search = strip_tags($search);
            $search = trim($search);

            $data = mysql_query("SELECT * FROM patient WHERE fname LIKE '%$search%'");

            while ($row = mysql_fetch_array($data)) {
                $message = "<div class='titleBox'>" . $row['fname'] . "</div>";
           }

          $matches = mysql_num_rows($data);

          if($matches === 0) {
            $message = "<div class='titleBox'>Sorry, but we can not find an entry to match your query.</div>";
          }
            $message1 = "<div class='titleBox'><b>Searched For:" . $search . "<b/></div>";
        }
      }

  ?>

 <form action="patient.php" method="post">

        <input type="text" class="subjectBox" autocomplete="off" name="search" placeholder="Enter a name to search..." style="margin: auto; display: block; margin-bottom: 5px; width: 595px;">
        <input type="submit" value="go." name="submit" class="titleBox" style="width: 595px; ">

              </form>

         <?php if(!empty($message1)): ?><p><?= $message1 ?></p><?php endif; ?>

         <?php if(!empty($message)): ?><p><?= $message ?></p><?php endif; ?>

0 个答案:

没有答案