Advertisement
Guest User

Untitled

a guest
May 30th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2. //if nothing is entered in the form as keyword, the user is redirected back to the form
  3. if(empty($_POST['keyword'])){
  4. header ("Location: index.html");
  5. exit;
  6. }
  7. ?>
  8.  
  9.  
  10.  
  11. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  12. <head>
  13. <title>Results</title>
  14. <style type="text/css">
  15. body, h2, tr { text-align: center }
  16. </style>
  17. </head>
  18. <body>
  19. <?php
  20.  
  21.  
  22. $criterias = array("sid", "firstname", "lastname", "address", "telephone", "dob");
  23. $criteriaForUser = array("Student ID", "First name", "Last name", "Address", "Telephone Number", "Date of birth");
  24. $servername = "localhost";
  25. $username = "root";
  26. $password = "";
  27. $dbname = "students";
  28. // Create connection
  29. $conn = new mysqli("localhost", "root", "", "students");
  30. // Check connection
  31. if ($conn->connect_error) {
  32. die("Connection failed: " . $conn->connect_error);
  33. }
  34. //if the user is here the field is not empty
  35. $keyword = mysqlclean($_POST['keyword'], 100, $connection);
  36. $criteria = $criterias[$_POST['criteria']];
  37. $criteriaForUser = $criteriaForUser[$_POST['criteria']];
  38. $order = trim($_POST['order']);
  39.  
  40. //Constructing the sql query
  41. $query = "SELECT * FROM student WHERE $criteria like '%$keyword%' ORDER BY $criteria $order";
  42.  
  43. //Runing the query through the connection
  44. if (!($result = @ mysql_query ($query, $connection)))
  45. dberror();
  46.  
  47. //Displaying the Results
  48. $rowsFound = @ mysql_num_rows($result);
  49. if ($rowsFound > 0){
  50. echo "<h2>Students with $criteriaForUser: $keyword</h2>";
  51. displayResults($result);
  52. }
  53. //Nothing matched
  54. else
  55. echo "<h2>No students with $criteriaForUser: $keyword</h2>";
  56. ?>
  57. <br/><a href="index.html"><< Back to Search</a>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement