Chalkie83

Untitled

Jan 28th, 2021 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. /* Setting Database Details */
  4.  
  5. $host = 'localhost';
  6. $username = '******';
  7. $password = '******';
  8. $dbname = '*********';
  9. $tbl = 'anime';
  10.  
  11. /* Setting SQL Argument */
  12.  
  13. $sql = 'SELECT * FROM ' .$tbl;
  14. $conn = new mysqli($host, $username, $password, $dbname);
  15. if ($conn->connect_error) {
  16. die("Connection failed: " . $conn->connect_error);
  17. }
  18.  
  19. $result = $conn->query($sql);
  20.  
  21. ?>
  22.  
  23.  
  24. <html>
  25. <head>
  26. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  27. <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
  28. <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
  29.  
  30. </head>
  31. <body>
  32. <form action="search.php" method="POST" class="search-bar">
  33. <select class="search" name="search">
  34. <?php
  35. while ($row = $result->fetch_assoc()) {
  36. echo '<option value="'.$row['a_title'].'" onclick="location.href=\''.$row['a_url'].'\'">'.$row['a_title'].'</option>';
  37. }
  38. if($result->num_rows == 0) { echo '<option value="blank">Nothing in the database or the database details are wrong</option>'; }
  39. ?>
  40.  
  41. </select>
  42. <button class="search-btn" type="submit" name="submit-search">
  43. <span>Search</span>
  44. </button>
  45. <script>
  46. $(document).ready(function() {
  47. $('.search').select2();
  48. });
  49. </script>
  50. </form>
  51. </body>
  52. </html>
Add Comment
Please, Sign In to add comment