Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. $query = $pdo->prepare("SELECT * FROM subs WHERE sub_title LIKE '%$search%' LIMIT 0, 10");
  2.  
  3. <?php
  4. require_once('includes/config.php');
  5. include("includes/header.php");
  6.  
  7. // Search from MySQL database table
  8. $search = $_POST['search'];
  9. $query = $pdo->prepare("SELECT * FROM subs WHERE sub_title LIKE '%$search%' LIMIT 0, 10");
  10. $query->bindValue(1, "%$search%", PDO::PARAM_STR);
  11. $query->execute();
  12.  
  13. // Display search result
  14. if(!$query->rowCount() == 0) {
  15. echo "Search found:<br>";
  16. echo "<table>";
  17. echo "<tr><td>Title</td><td>Category></td><td>Language</td><td>Time</td><td>Download</td></tr>";
  18. while($results = $query->fetch()) {
  19. echo "<tr><td>";
  20. echo $results['sub_title'];
  21. echo "</td><td>";
  22. echo $results['category'];
  23. echo "</td><td>";
  24. echo $results['sub_lang'];
  25. echo "</td><td>";
  26. echo $results['timestamp'];
  27. echo "</td><td>";
  28. echo $results['sub_data'];
  29. echo "</td></tr>";
  30. }
  31.  
  32. echo "</table>";
  33. } else {
  34. echo "Nothing found";
  35. }
  36.  
  37. ?>
  38.  
  39. <?php
  40. $username = '------';
  41. $password = '------';
  42.  
  43. try {
  44. $conn = new PDO('mysql:host=localhost;dbname=-----', $username, $password, array(
  45. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  46. ));
  47. }
  48.  
  49. catch(PDOException $e) {
  50. echo "Failed to connect to database!" . "<br><br>";
  51. echo $e->getMessage();
  52. }
  53. ?>
  54.  
  55. <form class="form-inline" action="search.php" method="POST">
  56. <input class="form-control" name="search" id="search" type="text" placeholder="Search">
  57. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement