SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
2 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
3 | - | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
3 | + | <head> |
4 | - | <html xmlns="http://www.w3.org/1999/xhtml"> |
4 | + | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
5 | - | <head> |
5 | + | <title>Book-O-Rama Search Results</title> |
6 | - | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
6 | + | </head> |
7 | - | <title>Book-O-Rama Search Results</title> |
7 | + | |
8 | - | </head> |
8 | + | <body> |
9 | - | |
9 | + | <h1>Book-O-Rama Search Results</h1> |
10 | - | <body> |
10 | + | <?php |
11 | - | <h1>Book-O-Rama Search Results</h1> |
11 | + | // create short variable names |
12 | - | <?php |
12 | + | $searchtype=$_POST['searchtype']; |
13 | - | // create short variable names |
13 | + | $searchterm=trim($_POST['searchterm']); |
14 | - | $searchtype=$_POST['searchtype']; |
14 | + | if (!$searchtype || !$searchterm) { |
15 | - | $searchterm=trim($_POST['searchterm']); |
15 | + | echo 'You have not entered search details. Please go back and try again.'; |
16 | - | if (!$searchtype || !$searchterm) { |
16 | + | exit; |
17 | - | echo 'You have not entered search details. Please go back and try again.'; |
17 | + | } |
18 | - | exit; |
18 | + | if (!get_magic_quotes_gpc()){ |
19 | - | } |
19 | + | $searchtype = addslashes($searchtype); |
20 | - | if (!get_magic_quotes_gpc()){ |
20 | + | $searchterm = addslashes($searchterm); |
21 | - | $searchtype = addslashes($searchtype); |
21 | + | } |
22 | - | $searchterm = addslashes($searchterm); |
22 | + | $dbhost = '213.171.200.57'; // your database server’s IP address |
23 | - | } |
23 | + | $dbuser = 'bookorama'; // the database username |
24 | - | @ $db = new mysqli('213.171.200.57', 'bookorama', 'password', 'books'); |
24 | + | $dbpass = 'password'; // the database password |
25 | - | if (mysqli_connect_errno()) { |
25 | + | $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('error connecting to |
26 | - | echo 'Error: Could not connect to database. Please try again later.'; |
26 | + | your database'); // opens a connection to the server or gives an error |
27 | - | exit; |
27 | + | $dbname = 'bookorama'; // the database name |
28 | - | } |
28 | + | mysql_select_db($dbname); // connects to your database |
29 | - | $query = "SELECT * FROM books WHERE ".$searchtype." like '%".$searchterm."%'"; |
29 | + | |
30 | - | $result = $db->query($query); |
30 | + | $query = "SELECT * FROM books WHERE ".$searchtype." like '%".$searchterm."%'"; |
31 | - | $num_results = $result->num_rows; |
31 | + | $result = $db->query($query); |
32 | - | echo "<p>Number of books found: ".$num_results."</p>"; |
32 | + | $num_results = $result->num_rows; |
33 | - | for ($i=0; $i <$num_results; $i++) { |
33 | + | echo "<p>Number of books found: ".$num_results."</p>"; |
34 | - | $row = $result->fetch_assoc(); |
34 | + | for ($i=0; $i <$num_results; $i++) { |
35 | - | echo "<p><strong>".($i+1).". Title: "; |
35 | + | $row = $result->fetch_assoc(); |
36 | - | echo htmlspecialchars(stripslashes($row['title'])); |
36 | + | echo "<p><strong>".($i+1).". Title: "; |
37 | - | echo "</strong><br />Author: "; |
37 | + | echo htmlspecialchars(stripslashes($row['title'])); |
38 | - | echo stripslashes($row['author']); |
38 | + | echo "</strong><br />Author: "; |
39 | - | echo "<br />ISBN: "; |
39 | + | echo stripslashes($row['author']); |
40 | - | echo stripslashes($row['isbn']); |
40 | + | echo "<br />ISBN: "; |
41 | - | echo "<br />Price: "; |
41 | + | echo stripslashes($row['isbn']); |
42 | - | echo stripslashes($row['price']); |
42 | + | echo "<br />Price: "; |
43 | - | echo "</p>"; |
43 | + | echo stripslashes($row['price']); |
44 | - | } |
44 | + | echo "</p>"; |
45 | - | $result->free(); |
45 | + | } |
46 | - | $db->close(); |
46 | + | $result->free(); |
47 | - | ?> |
47 | + | $db->close(); |
48 | - | </body> |
48 | + | ?> |
49 | - | </html> |
49 | + | </body> |
50 | </html> |