Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. <?php
  2. /* Start the session */
  3. session_start();
  4. /* link to the functions.php page */
  5. require_once('functions.php');
  6. ?>
  7.  
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  9. <html>
  10. <head>
  11. <title>Search</title>
  12. <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  13. <!-- CSS to manage the color of the links -->
  14. <style type = "text/css">
  15. A:link {text-decoration: underline; color: white;}
  16. A:visited {text-decoration: underline; color: black}
  17. A:hover {text-decoration: underline; color: red;}
  18. </style>
  19. <link rel="stylesheet" type="text/css" href="format.css">
  20.  
  21. <!-- Javascript for the Live Search -->
  22. <script type="text/javascript">
  23. function Show(input, option)
  24. {
  25. //If the length of the input is zero
  26. if (input.length == 0)
  27. {
  28. //Hide the box
  29. document.getElementById("suggestion").innerHTML = "";
  30. document.getElementById("suggestion").style.border = "0px";
  31. return;
  32. }
  33.  
  34. if (window.XMLHttpRequest)
  35. {
  36. // code for IE7+, Firefox, Chrome, Opera, Safari
  37. xmlhttp=new XMLHttpRequest();
  38. }
  39. xmlhttp.onreadystatechange=function()
  40. {
  41. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  42. {
  43. document.getElementById("suggestion").innerHTML=xmlhttp.responseText;
  44. document.getElementById("suggestion").style.border="1px solid #A5ACB2";
  45.  
  46. if( document.getElementById("suggestion").innerHTML == '' )
  47. {
  48. document.getElementById("suggestion").style.display = "none";
  49. }
  50. else
  51. {
  52. document.getElementById("suggestion").style.display = "block";
  53. }
  54. }
  55. }
  56. xmlhttp.open("GET","livesearch.php?Search="+input+"&SearchType="+option ,true);
  57. xmlhttp.send();
  58. }
  59. </script>
  60. </head>
  61.  
  62. <body class = "background-main">
  63. <div id = "linkDiv" class = "align-center spacing background-links">
  64. <!-- The heading of the website -->
  65. <h1 style = "word-spacing:0px">Disarm Anime Warehouse</h1>
  66. <!-- A list of links to the other pages -->
  67. <a href = "ass2.php">Home</a>
  68. <a href = "information.php">Information</a>
  69. <a href = "product.php">Products</a>
  70. <a href = "faq.php">FAQ/Help</a>
  71. <a href = "contact.php">Contact</a>
  72. </div>
  73.  
  74. <!-- Add a horizontal rule -->
  75. <hr>
  76.  
  77. <!-- Heading -->
  78. <h2 class="align-center">Search for a Product</h2>
  79.  
  80. <!-- Display the shopping cart information -->
  81. <?php echo(writeShoppingCart()); ?>
  82.  
  83. <p class = "align-center">Use the form below to search for a product on our website</p>
  84.  
  85. <div id ="searchDiv" class = "align-center">
  86. <!-- Create a form -->
  87. <form action = "search.php" method = "get">
  88. <!-- A drop down list to allow the user to select what they wish to search by -->
  89. Search By: <select name = "searchOption" id = "searchOption">
  90. <option value = "Name" <?php if( $_GET['searchOption'] == "Name") echo "selected"; ?>>Name</option>
  91. <option value = "Series" <?php if( $_GET['searchOption'] == "Series") echo "selected"; ?>>Series</option>
  92. <option value = "ReleaseDate" <?php if( $_GET['searchOption'] == "ReleaseDate") echo "selected"; ?>>Release Date</option>
  93. <option value = "Price" <?php if( $_GET['searchOption'] == "Price") echo "selected"; ?>>Price</option>
  94. </select>
  95. <!-- A field for the user to enter what they wish to search for -->
  96. <input name = "search" id = "search" type = "text" size = "30" value="<?php echo $_GET['search'] ?>" onkeyup="Show(this.value, searchOption.value)">
  97.  
  98. <!-- A Submit Button -->
  99. <input type = "submit" value = "Submit">
  100.  
  101. <br>
  102.  
  103. <!-- Section to display the Live Search results -->
  104. <div id = "suggestion" style="width:350px"></div>
  105.  
  106. </form>
  107. </div>
  108.  
  109. <?php
  110. /* Check if the search is being conducted */
  111. if(isset($_GET['searchOption']) && isset($_GET['search']))
  112. {
  113. /* Connect to the database */
  114. $user = "dsar";
  115. $pass = "(W6rIXNF";
  116. $db = "SSID";
  117. $connect = OCILogon($user, $pass, $db);
  118.  
  119. /* Return an error message if the logon fails */
  120. if(!connect)
  121. {
  122. echo "An error occured connecting to the database";
  123. exit;
  124. }
  125.  
  126. /* Retrieves the value from the textbox and store it in a variable */
  127. $search = $_REQUEST['search'];
  128.  
  129. /* Retrieves the selected option from the drop down list and store it in a variable */
  130. $searchOption = $_REQUEST['searchOption'];
  131.  
  132.  
  133. /* Create the SQL statement */
  134. $searchQuery = "SELECT * FROM Products WHERE UPPER(" .$searchOption. ") LIKE UPPER('%" . $search . "%')";
  135.  
  136. /* parse the sql string */
  137. $stmt = OCIParse($connect, $searchQuery);
  138.  
  139. /* Returns an error message if the parsing failed */
  140. if (!stmt)
  141. {
  142. echo "An error occurred in parsing the sql string.";
  143. exit;
  144. }
  145.  
  146. OCIExecute($stmt);
  147.  
  148. /* A variable to check if the search returned any results */
  149. $found = false;
  150.  
  151. /* create the table */
  152. echo("<table border = 2>");
  153.  
  154. /*while there are more records*/
  155. while(OCIFetch($stmt))
  156. {
  157. /* results were found */
  158. $found = true;
  159.  
  160. /*output the products from the database*/
  161. echo("<tr>");
  162. /*Store the name field in a variable and output it*/
  163. $name = OCIResult($stmt, "NAME");
  164. echo("<th colspan=2 class='align-center'>");
  165. echo($name);
  166. echo("</th>");
  167. echo("</tr>");
  168.  
  169. echo("<tr>");
  170. /*Store the rest of the fields into variable*/
  171. $series = OCIResult($stmt, "SERIES");
  172. $date = OCIResult($stmt, "RELEASEDATE");
  173. $price = OCIResult($stmt, "PRICE");
  174. $description = OCIResult($stmt, "DESCRIPTION");
  175. $image = OCIResult($stmt, "IMAGE");
  176.  
  177. /*Display the image*/
  178. echo("<td>");
  179. echo("<img src=".$image." alt=".$image.">");
  180. echo("</td>");
  181.  
  182. /*Display the rest of the data*/
  183. echo("<td>");
  184. echo ('<a href="cart.php?option=add&ID=' . OCIResult($stmt,"ID") . '" style="color:black"> Add to Cart </a>');
  185. echo("<ul>");
  186. echo("<li>Series: " .$series. "</li>");
  187. echo("<li>Release Date: " .$date. "</li>");
  188. echo("<li>Price: $" .$price. "</li>");
  189. echo("<li>Description: " .$description. "</li>");
  190. echo("</ul>");
  191. echo("</td>");
  192. echo("</tr>");
  193. }
  194. echo("</table>");
  195.  
  196. /* If no results were found */
  197. if ($found == false)
  198. {
  199. /* Display error message */
  200. echo "<p style='text-align:center; font-size:1.2em;'>Your search returned no results </p>";
  201. }
  202.  
  203. /* Disconnects from database */
  204. OCILogOff($connect);
  205. }
  206. ?>
  207.  
  208. <p>"&copy;Deakin University, School of Information Technology. This web page has been developed as a
  209. student assignment for the unit SIT203: Web Programming. Therefore it is not part of the University's authorised web site.
  210. DO NOT USE THE INFORMATION CONTAINED ON THIS WEB PAGE IN ANY WAY."</p>
  211. </body>
  212. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement