Advertisement
michaelyuen

Untitled

Mar 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require 'dbconnect.php';
  4. ?>
  5. <!DOCTYPE html>
  6. <html>
  7.     <head>
  8.     <title>Untitled Document</title>
  9.     </head>
  10.     <body>
  11.         <form name="formbrowseone" action="" method="POST" enctype="multipart/form-data">
  12.             <input type="text" name="query" />
  13.             <input type="submit" value="Search" />
  14.         </form>
  15. <?php
  16. if (isset($_POST['query'])) {
  17.     echo '<title>Search results</title>';
  18.     $search = '%' . $_POST['query'] . '%';
  19.     $newsearch = filter_var($search, FILTER_SANITIZE_STRING);
  20.     $query = "SELECT * FROM useradvert WHERE adtitle LIKE ?";
  21.     $select = $conn->prepare($query);
  22.     $select->bind_param('s', $newsearch);
  23.     $select->execute();
  24.     $result = $select->get_result();
  25.     if ($result->num_rows($result) > 0) { // updated
  26.         WHILE ($row = $result->fetch_assoc()){
  27.             echo $row['adtitle'];
  28.         }
  29.     } else {
  30.         // if there is no matching rows do following
  31.         echo "No results";
  32.     }
  33. }
  34. ?>
  35.     </body>
  36. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement