Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //if nothing is entered in the form as keyword, the user is redirected back to the form
- if(empty($_POST['keyword'])){
- header ("Location: index.html");
- exit;
- }
- ?>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Results</title>
- <style type="text/css">
- body, h2, tr { text-align: center }
- </style>
- </head>
- <body>
- <?php
- $criterias = array("sid", "firstname", "lastname", "address", "telephone", "dob");
- $criteriaForUser = array("Student ID", "First name", "Last name", "Address", "Telephone Number", "Date of birth");
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "students";
- // Create connection
- $conn = new mysqli("localhost", "root", "", "students");
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //if the user is here the field is not empty
- $keyword = mysqlclean($_POST['keyword'], 100, $connection);
- $criteria = $criterias[$_POST['criteria']];
- $criteriaForUser = $criteriaForUser[$_POST['criteria']];
- $order = trim($_POST['order']);
- //Constructing the sql query
- $query = "SELECT * FROM student WHERE $criteria like '%$keyword%' ORDER BY $criteria $order";
- //Runing the query through the connection
- if (!($result = @ mysql_query ($query, $connection)))
- dberror();
- //Displaying the Results
- $rowsFound = @ mysql_num_rows($result);
- if ($rowsFound > 0){
- echo "<h2>Students with $criteriaForUser: $keyword</h2>";
- displayResults($result);
- }
- //Nothing matched
- else
- echo "<h2>No students with $criteriaForUser: $keyword</h2>";
- ?>
- <br/><a href="index.html"><< Back to Search</a>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement