Advertisement
michaelyuen

Untitled

Jul 31st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors',1); // enable php error display for easy trouble shooting
  3. error_reporting(E_ALL); // set error display to all
  4.  
  5. $connect = mysqli_connect("localhost", "root", "", "signup_confirm") or die("Error " . mysqli_error($con));
  6.  
  7. if (isset($_POST['search'])) {
  8.     $valueToSearch = mysqli_real_escape($connect, $_POST['valueToSearch']);
  9.     $query = "SELECT * FROM `form` WHERE CONCAT(`student_name`, `city`) LIKE '%".$valueToSearch."%'";
  10.     // don't know what you are trying to search with CONCAT
  11.     // you may try $query = "SELECT * FROM `form` WHERE `student_name` LIKE '%".$valueToSearch."%' OR `city` LIKE '%".$valueToSearch."%'";
  12.     $search_result = filterTable($query);
  13. } else {
  14.     $query = "SELECT * FROM `form`";
  15.     $search_result = filterTable($query);
  16. }
  17.  
  18. function filterTable($query) {
  19.     global $connect;
  20.     if (!$result = mysqli_query($connect, $query)) {
  21.         return false;
  22.     } else {
  23.         return $result;
  24.     }
  25. }
  26.  
  27. ?>
  28. <!DOCTYPE html>
  29. <html>
  30. <head>
  31.     <title>PHP HTML TABLE DATA SEARCH</title>
  32.     <style>
  33.     table,tr,th,td {
  34.     border: 1px solid black;
  35.     }
  36.     </style>
  37. </head>
  38. <body>
  39. <div align="right">
  40.     <form action="" method="post">
  41.         <input type="text" name="valueToSearch" placeholder="Value To Search" size="40"><br><br>
  42.         <input type="submit" name="search" value="Search Now"><br><br>
  43.     </form>
  44. </div>
  45. <table width="1000" border="5" align="center">
  46.     <tr>
  47.         <h1><td colspan="9" align="center" bgcolor="blue"><h1>viewing all the records</h1></td></h1>
  48.     </tr>
  49.     <tr align="center">
  50.         <th>serial no</th>
  51.         <th>Name</th>
  52.         <th>last Name</th>
  53.         <th>father number</th>
  54.         <th>Nic</th>
  55.         <th>mobile number</th>
  56.         <th>Blood group</th>
  57.         <th>gender</th>
  58.         <th>city</th>
  59.     </tr>
  60. <?php
  61.     if (!$search_result) {
  62.         die('Error :' . mysqli_error($connect));
  63.     } else {
  64.         if (mysqli_num_rows($search_result) == 0) {
  65.             echo '<tr><td colspan="9">no record found</td></tr>';
  66.         } else {
  67.             WHILE ($row = mysqli_fetch_array($search_result)) {
  68.                 echo "<tr>";
  69.                 echo "<td>{$row['id']}</td>";
  70.                 echo "<td>{$row['name']}</td>";
  71.                 echo "<td>{$row['last_name']}</td>";
  72.                 echo "<td>{$row['f_name']}</td>";
  73.                 echo "<td>{$row['nic']}</td>";
  74.                 echo "<td>{$row['mobile']}</td>";
  75.                 echo "<td>{$row['blood_group']}</td>";
  76.                 echo "<td>{$row['gender']}</td>";
  77.                 echo "<td>{$row['city']}</td>";
  78.                 echo "</tr>";  
  79.             }
  80.         }
  81.     }
  82. ?>
  83.         </table>
  84.     </body>
  85. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement