Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <html>
  2. <head><title>Searching for item...</title>
  3. </head>
  4. <body bgcolor=#ffffff>
  5.  
  6. <?php
  7. $username = "admin";
  8. $password = "admin";
  9. $hostname = "localhost";
  10. $port = "50000";
  11. $database="HLDB";
  12.  
  13. $conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;"."HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$username;PWD=$password";
  14.  
  15. $conn = odbc_connect($conn_string, '', '');
  16.  
  17. echo "<h2>Search Results:</h2><p>";
  18.  
  19. //Retrieve input from find field on previous page and store in a variable
  20. $find = $_POST['find'];
  21.  
  22. echo "User searched for: " . $find . "<br><br>";
  23.  
  24. //If they did not enter a search term we give them an error
  25. if ($find == "")
  26. {
  27. echo "<p>Please scan for an item!";
  28. exit;
  29. }
  30.  
  31. // Otherwise we connect to our Database
  32. if ($conn){
  33. echo "Connection succeeded. n";
  34. odbc_close($conn);
  35. }
  36. else{
  37. echo "Connection failed. n";
  38. }
  39.  
  40. //Now we search for our search term, in the field the user specified
  41. $sql = "SELECT * FROM NULLID.ITEMS WHERE 'ITEM NO.' LIKE '%$find%'";
  42.  
  43. $rs=odbc_exec($conn,$sql);
  44.  
  45. //fetch tha data from the database
  46. while(odbc_fetch_row($rs))
  47. {
  48. //display the data
  49. echo odbc_result($rs, "Description 1"), "n";
  50. }
  51.  
  52. //This counts the number or results - and if there wasn't any it gives them a little message explaining that
  53. $anymatches=odbc_num_rows($sql);
  54. if ($anymatches == 0)
  55. {
  56. echo "Sorry, but we are unable to find this product...<br><br>";
  57. }
  58.  
  59. //And we remind them what they searched for
  60. echo "<b>Searched For:</b> " .$find;
  61. ?>
  62.  
  63.  
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement