Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- @mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
- mysql_select_db("inv") or die(mysql_error());
- if($_SERVER['REQUEST_METHOD'] == 'POST'){
- // check if the cart has anything in it
- if(!isset($_SESSION['cart'])) $_SESSION['cart'] = null;
- // validate something is there
- if($_POST['qty'] >= 0) {
- // add the qty to the PID. Store it in the session array with the PID as the key
- // $_SESSION['cart'][$_POST['add_to_cart']] = $_POST['qty'];
- $_SESSION['cart'][$_POST['pid']] = $_POST['qty'];
- }
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Inventory Search Results - Secaucus</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <img src="images.jpg" alt="logo" height="98" width="300"> <br><br>
- <h3> Inventory Results - Secaucus Warehouse</h3><hr>
- <?php
- $query = $_GET['query'];
- // gets value sent over search form
- $min_length = 3;
- // set minimum length of the query
- if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
- $query = htmlspecialchars($query);
- // changes characters used in html to their equivalents
- $query = mysql_real_escape_string($query);
- // makes sure nobody uses SQL injection
- $raw_results = mysql_query("SELECT * FROM products
- WHERE (`PID` LIKE '%".$query."%') OR (`Description` LIKE '%".$query."%') ORDER BY PID") or die(mysql_error());
- /*$assoc = mysql_fetch_assoc($raw_results);
- var_dump($assoc);*/
- if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
- $i = "1";
- while($results = mysql_fetch_array($raw_results)){
- echo "<h3><div id='$i'>Product ID: ".$results['PID']."</div></h3>";
- echo "<p>Description: ".$results['Description']."</p>";
- echo "<p>Quantity: ".$results['Quantity']."</p>";
- echo "<p>Location: ".$results['Location']."</p>";
- // echo "<p>Link: ".$results['DataSheetLink']."</p>";
- if(!empty($results['DataSheetLink']))
- echo '<p>Data Sheet Link: <a href="'.$results['DataSheetLink'].'">Click Here</a></p>';
- echo "<a href='mailto:marc.e.cerone@jci.com?subject=Part Request: ".$results['PID']."&body=I would like to request (enter quantity of this item) of PID ".$results['PID']." - ".$results['Description']." '>Request Item</a><br><br>";
- echo "<form method='post'>";
- echo "<input type='text' id='qty$i' name='qty' value='' placeholder='Quantity' width='50px' />";
- echo '<input type="hidden" name="pid" value="'.$results['PID'].'">';
- echo '<button name="add_to_cart" value="'.$results['PID'].'" type="submit">Add to List</button><br>';
- echo "</form>"; echo "<hr>";
- $i++;
- // posts results gotten from database
- }
- if(isset($_SESSION['cart'])){
- $items = "";
- foreach($_SESSION['cart'] as $key => $value) {
- $items .= "$key, $value\n";
- }
- }
- if(!empty($items))
- echo $items;
- }
- else{ // if there is no matching rows do following
- echo "Sorry, No results were found";
- }
- }
- else{ // if query length is less than minimum
- echo "Minimum length is ".$min_length;
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement