Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Start the session */
- session_start();
- /* link to the functions.php page */
- require_once('functions.php');
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Search</title>
- <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
- <!-- CSS to manage the color of the links -->
- <style type = "text/css">
- A:link {text-decoration: underline; color: white;}
- A:visited {text-decoration: underline; color: black}
- A:hover {text-decoration: underline; color: red;}
- </style>
- <link rel="stylesheet" type="text/css" href="format.css">
- <!-- Javascript for the Live Search -->
- <script type="text/javascript">
- function Show(input, option)
- {
- //If the length of the input is zero
- if (input.length == 0)
- {
- //Hide the box
- document.getElementById("suggestion").innerHTML = "";
- document.getElementById("suggestion").style.border = "0px";
- return;
- }
- if (window.XMLHttpRequest)
- {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("suggestion").innerHTML=xmlhttp.responseText;
- document.getElementById("suggestion").style.border="1px solid #A5ACB2";
- if( document.getElementById("suggestion").innerHTML == '' )
- {
- document.getElementById("suggestion").style.display = "none";
- }
- else
- {
- document.getElementById("suggestion").style.display = "block";
- }
- }
- }
- xmlhttp.open("GET","livesearch.php?Search="+input+"&SearchType="+option ,true);
- xmlhttp.send();
- }
- </script>
- </head>
- <body class = "background-main">
- <div id = "linkDiv" class = "align-center spacing background-links">
- <!-- The heading of the website -->
- <h1 style = "word-spacing:0px">Disarm Anime Warehouse</h1>
- <!-- A list of links to the other pages -->
- <a href = "ass2.php">Home</a>
- <a href = "information.php">Information</a>
- <a href = "product.php">Products</a>
- <a href = "faq.php">FAQ/Help</a>
- <a href = "contact.php">Contact</a>
- </div>
- <!-- Add a horizontal rule -->
- <hr>
- <!-- Heading -->
- <h2 class="align-center">Search for a Product</h2>
- <!-- Display the shopping cart information -->
- <?php echo(writeShoppingCart()); ?>
- <p class = "align-center">Use the form below to search for a product on our website</p>
- <div id ="searchDiv" class = "align-center">
- <!-- Create a form -->
- <form action = "search.php" method = "get">
- <!-- A drop down list to allow the user to select what they wish to search by -->
- Search By: <select name = "searchOption" id = "searchOption">
- <option value = "Name" <?php if( $_GET['searchOption'] == "Name") echo "selected"; ?>>Name</option>
- <option value = "Series" <?php if( $_GET['searchOption'] == "Series") echo "selected"; ?>>Series</option>
- <option value = "ReleaseDate" <?php if( $_GET['searchOption'] == "ReleaseDate") echo "selected"; ?>>Release Date</option>
- <option value = "Price" <?php if( $_GET['searchOption'] == "Price") echo "selected"; ?>>Price</option>
- </select>
- <!-- A field for the user to enter what they wish to search for -->
- <input name = "search" id = "search" type = "text" size = "30" value="<?php echo $_GET['search'] ?>" onkeyup="Show(this.value, searchOption.value)">
- <!-- A Submit Button -->
- <input type = "submit" value = "Submit">
- <br>
- <!-- Section to display the Live Search results -->
- <div id = "suggestion" style="width:350px"></div>
- </form>
- </div>
- <?php
- /* Check if the search is being conducted */
- if(isset($_GET['searchOption']) && isset($_GET['search']))
- {
- /* Connect to the database */
- $user = "dsar";
- $pass = "(W6rIXNF";
- $db = "SSID";
- $connect = OCILogon($user, $pass, $db);
- /* Return an error message if the logon fails */
- if(!connect)
- {
- echo "An error occured connecting to the database";
- exit;
- }
- /* Retrieves the value from the textbox and store it in a variable */
- $search = $_REQUEST['search'];
- /* Retrieves the selected option from the drop down list and store it in a variable */
- $searchOption = $_REQUEST['searchOption'];
- /* Create the SQL statement */
- $searchQuery = "SELECT * FROM Products WHERE UPPER(" .$searchOption. ") LIKE UPPER('%" . $search . "%')";
- /* parse the sql string */
- $stmt = OCIParse($connect, $searchQuery);
- /* Returns an error message if the parsing failed */
- if (!stmt)
- {
- echo "An error occurred in parsing the sql string.";
- exit;
- }
- OCIExecute($stmt);
- /* A variable to check if the search returned any results */
- $found = false;
- /* create the table */
- echo("<table border = 2>");
- /*while there are more records*/
- while(OCIFetch($stmt))
- {
- /* results were found */
- $found = true;
- /*output the products from the database*/
- echo("<tr>");
- /*Store the name field in a variable and output it*/
- $name = OCIResult($stmt, "NAME");
- echo("<th colspan=2 class='align-center'>");
- echo($name);
- echo("</th>");
- echo("</tr>");
- echo("<tr>");
- /*Store the rest of the fields into variable*/
- $series = OCIResult($stmt, "SERIES");
- $date = OCIResult($stmt, "RELEASEDATE");
- $price = OCIResult($stmt, "PRICE");
- $description = OCIResult($stmt, "DESCRIPTION");
- $image = OCIResult($stmt, "IMAGE");
- /*Display the image*/
- echo("<td>");
- echo("<img src=".$image." alt=".$image.">");
- echo("</td>");
- /*Display the rest of the data*/
- echo("<td>");
- echo ('<a href="cart.php?option=add&ID=' . OCIResult($stmt,"ID") . '" style="color:black"> Add to Cart </a>');
- echo("<ul>");
- echo("<li>Series: " .$series. "</li>");
- echo("<li>Release Date: " .$date. "</li>");
- echo("<li>Price: $" .$price. "</li>");
- echo("<li>Description: " .$description. "</li>");
- echo("</ul>");
- echo("</td>");
- echo("</tr>");
- }
- echo("</table>");
- /* If no results were found */
- if ($found == false)
- {
- /* Display error message */
- echo "<p style='text-align:center; font-size:1.2em;'>Your search returned no results </p>";
- }
- /* Disconnects from database */
- OCILogOff($connect);
- }
- ?>
- <p>"©Deakin University, School of Information Technology. This web page has been developed as a
- student assignment for the unit SIT203: Web Programming. Therefore it is not part of the University's authorised web site.
- DO NOT USE THE INFORMATION CONTAINED ON THIS WEB PAGE IN ANY WAY."</p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement