Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <form action="search.php" method="post" id="search">
  2. <div id="searchfield_div">
  3. <input name="search" id="searchfield" type="text" placeholder="What you looking for?">
  4. <input id="delete_search_button" name="delete button" type="button" value="X">
  5. <input id="search_button" name="search button" type="submit" value="Search">
  6. </div>
  7. </form>
  8.  
  9. <?php
  10. //connection script
  11. $db_host = "localhost";
  12. $db_user = "root";
  13. $db_pass = "";
  14. $db_name = "liquihub";
  15. $output = '';
  16.  
  17. @mysqli_connect("$db_host","$db_user","$db_pass","$db_name") or die("could not connect");
  18.  
  19. //collection script
  20. if (isset($_POST['search'])) {
  21. $searchq = $_POST['search'];
  22. $searchq = preg_replace("#[^0-9a-z]#i","", $searchq);
  23.  
  24. $query = mysql_query("SELECT * FROM beverage_db WHERE name LIKE '%$searchq%' OR price LIKE '%$searchq%' OR type LIKE '%$searchq%'") or die ("could not search" );
  25. $count = mysql_num_rows($query);
  26. if ($count == 0) {
  27. $output = 'We not stocking this particular item at present';
  28. }else{
  29. while($row = mysql_fetch_array($query)) {
  30. $bevname = $row['name'];
  31. $bevprice = $row['price'];
  32. $bevtype = $row['type'];
  33. $bevid = $row['id'];
  34.  
  35. $output .= '<div>'.$bevname.' '.$bevprice.' '.$bevtype.'</div>';
  36. }
  37. }
  38. }
  39. ?>
  40.  
  41. <?php print("$output");?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement