Advertisement
Guest User

Untitled

a guest
Mar 5th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. // Connect to DB
  4. $servername = "";
  5. $username = "";
  6. $password = "";
  7. $dbname = "";
  8.  
  9. // Create connection
  10. $conn = new MySQLi($servername, $username, $password, $dbname);
  11.  
  12. // Check connection
  13. if ($conn->connect_error) {
  14. die("Connection failed: " . $conn->connect_error);
  15. }
  16.  
  17. // Collect Data
  18. // Ensure user input string only has letter characters
  19. // Unimportant to current problem
  20. if(isset($_POST["aSearch"])) {
  21. $searchq = $_POST["aSearch"];
  22. $searchq = preg_replace("#[^0-9a-z]#i","",$searchq); //Can only search words
  23.  
  24. // Select records which match the user's input
  25. $sql = "SELECT * FROM birdt WHERE birdName LIKE '%$searchq%'";
  26. }
  27.  
  28. // Tests if the code been inserted
  29. if ($conn->query($sql)=== TRUE){
  30. echo "The rows you have searched for are:";
  31. } else {
  32. echo "Connection failed: ";
  33. echo $conn->error;
  34. }
  35.  
  36. // Show fields
  37. $result = $conn->query($sql);
  38.  
  39. // Output data of each row
  40. if ($result-> num_rows> 0) {
  41. readfile("ViewReturn.html"); // Returns the file in an HTML Page
  42. while($row = $result-> fetch_assoc()) {
  43. // echo "ID: ".$row["id"]. "<br>";
  44. echo "Bird Name: ".$row["birdName"]. "<br><br>";
  45. }
  46. } else {
  47. echo "0 results";
  48. }
  49.  
  50. // Close connections
  51. if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
  52. echo "There was an error with MySQLi";
  53. } else {
  54. echo "Closing Connections";
  55. }
  56.  
  57. $conn-> close();
  58. exit();
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement