2017-06-02 12 views
-1

データベースをフィルタリングする際に問題がありますが、このコードはありますが、送信ボタンをクリックした後にフィルタリングされたデータベースは表示されません。テキストボックスとドロップダウンリストを使用してデータベースをフィルタリングする(リアルタイム検索)

<form method="POST" action="client.php"> 
<div id="Search" style="display:none"> 
    <h4>Search Client</h4> 
     <table> 
      <tr> 
       <td> 
        <input type="text" name="text" placeholder="Keyword" /> 
       </td> 
       <td> 
        &nbsp &nbsp 
       </td> 
       <td> 
        <select id="search_by" name="search_by"> 
        <option value="Reference">Reference</option> 
        <option value="Lastname">Lastname</option> 
        <option value="Firstname">Firstname</option> 
        <option value="Province">Province</option> 
        <option value="Request">Request</option> 
        <option value="Status">Status</option> 
        </select> 
       </td> 
       <td> 
        &nbsp &nbsp 
       </td> 
       <td> 
        <input type="submit" name="btn_search" value="Search"> 
       </td> 
      </tr> 
     </table> 
     <br> 
     <?php 
     $res=mysqli_query($con,"SELECT*FROM client_info"); 
     echo "<table style='font-size:12px;border-spacing:5px; background-color:white; width:100%;'>"; 
     echo "<tr>"; 
     echo "<th> Reference No </th>"; 
     echo "<th> Lastname </th>"; 
     echo "<th> Firstname </th>"; 
     echo "<th> Middlename </th>"; 
     echo "<th> Street </th>"; 
     echo "<th> Brgy </th>"; 
     echo "<th> Town </th>"; 
     echo "<th> Prov </th>"; 
     echo "<th> Mobile </th>"; 
     echo "<th> Email </th>"; 
     echo "<th> Event </th>"; 
     echo "<th> Venue </th>"; 
     echo "<th> No. of Attendants </th>"; 
     echo "<th> Request </th>"; 
     echo "<th> Payment Ammount </th>"; 
     echo "<th> Payment Status </th>"; 
     echo "</tr>"; 
     while ($row=mysqli_fetch_array($res)) { 
      echo "<tr>"; 
      echo "<td>". $row["ref_no"] . "</td>"; 
      echo "<td>". $row["last_name"] . "</td>"; 
      echo "<td>". $row["first_name"] . "</td>"; 
      echo "<td>". $row["middle_name"] . "</td>"; 
      echo "<td><center>". $row["street"] . "</center></td>"; 
      echo "<td><center>". $row["brgy"] . "</center></td>"; 
      echo "<td><center>". $row["town"] . "</center></td>"; 
      echo "<td><center>". $row["prov"] . "</center></td>"; 
      echo "<td><center>". $row["mobile"] . "</center></td>"; 
      echo "<td><center>". $row["email_add"] . "</center></td>"; 
      echo "<td><center>". $row["event"] . "</center></td>"; 
      echo "<td><center>". $row["venue"] . "</center></td>"; 
      echo "<td><center>". $row["number_attendants"] . "</center></td>"; 
      echo "<td><center>". $row["request_res"] . "</center></td>"; 
      echo "<td><center>". $row["payment_amount"] . "</center></td>"; 
      echo "<td><center>". $row["payment_res"] . "</center></td>"; 
      echo "</tr>"; 
     } 
     echo "</table>"; 
     ?> 
    </form> 
    <?php 
    if (isset($_POST['btn_search'])) { 
     if ($_POST['search_by'] == 'Reference') { 
      $res=mysqli_query($con,"SELECT*FROM client_info WHERE ref_no LIKE '%".$_POST['text']."%'"); 
      echo "<table style='font-size:12px;border-spacing:5px; background-color:white; width:100%;'>"; 
      echo "<tr>"; 
      echo "<th> Reference No </th>"; 
      echo "<th> Lastname </th>"; 
      echo "<th> Firstname </th>"; 
      echo "<th> Middlename </th>"; 
      echo "<th> Street </th>"; 
      echo "<th> Brgy </th>"; 
      echo "<th> Town </th>"; 
      echo "<th> Prov </th>"; 
      echo "<th> Mobile </th>"; 
      echo "<th> Email </th>"; 
      echo "<th> Event </th>"; 
      echo "<th> Venue </th>"; 
      echo "<th> No. of Attendants </th>"; 
      echo "<th> Request </th>"; 
      echo "<th> Payment Ammount </th>"; 
      echo "<th> Payment Status </th>"; 
      echo "</tr>"; 
     while ($row=mysqli_fetch_array($res)) { 
      echo "<tr>"; 
      echo "<td>". $row["ref_no"] . "</td>"; 
      echo "<td>". $row["last_name"] . "</td>"; 
      echo "<td>". $row["first_name"] . "</td>"; 
      echo "<td>". $row["middle_name"] . "</td>"; 
      echo "<td><center>". $row["street"] . "</center></td>"; 
      echo "<td><center>". $row["brgy"] . "</center></td>"; 
      echo "<td><center>". $row["town"] . "</center></td>"; 
      echo "<td><center>". $row["prov"] . "</center></td>"; 
      echo "<td><center>". $row["mobile"] . "</center></td>"; 
      echo "<td><center>". $row["email_add"] . "</center></td>"; 
      echo "<td><center>". $row["event"] . "</center></td>"; 
      echo "<td><center>". $row["venue"] . "</center></td>"; 
      echo "<td><center>". $row["number_attendants"] . "</center></td>"; 
      echo "<td><center>". $row["request_res"] . "</center></td>"; 
      echo "<td><center>". $row["payment_amount"] . "</center></td>"; 
      echo "<td><center>". $row["payment_res"] . "</center></td>"; 
      echo "</tr>"; 
     } 
     echo "</table>"; 
     } 
    } 
    ?> 
</div> 
+0

なぜ3倍の文章を繰り返しましたか? –

+0

トリプルX効果? :p –

+0

Xander Cageはこちらです! –

答えて

1

私はそれががフィルタリングされた結果を示しんだと思います。毎回フィルタリングされていない結果を出力しているので、検索フォームが提出されていればフィルタリングされた結果を出力しているためではないようです。検索フォームが提出されたかどうかに応じて、異なるクエリを実行するだけです。このようなもの。

// search form 

if (isset($_POST['btn_search'])) { 
    if ($_POST['search_by'] == 'Reference') { 
     $res = mysqli_query($con, "SELECT * FROM client_info WHERE ref_no LIKE '%".$_POST['text']."%'"); 
    } 
} else { 
    $res = mysqli_query($con, "SELECT * FROM client_info"); 
} 

// display your query results 

また、クエリはSQLインジェクションに対して脆弱です。これはここでの問題点の横にありますが、ポスト値をSQLに連結するのではなく、プリペアドステートメントを使用して調べる必要があります。