SHARE
TWEET

Untitled

a guest Aug 12th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.    
  3. // since this is a one page tutorial
  4. // we're not seperating out the database connection
  5.  
  6. $db_host        = 'localhost';
  7. $db_user        = 'root';
  8. $db_password    = '!@#$#$';
  9. $db_name        = 'tw_data';
  10.    
  11.    
  12. $db = new mysqli($db_host , $db_user ,$db_password, $db_name);
  13.  
  14. if(!$db) {
  15.     // If there is an error, show this message.
  16.     echo 'There was a problem connecting to the database';
  17. } else {
  18.     // Check the user has typed something in our input box.
  19.     if(isset($_POST['mysearchString'])) {
  20.         $mysearchString = $db->real_escape_string($_POST['mysearchString']);
  21.        
  22.         // Is the string length greater than 0?
  23.        
  24.         if(strlen($mysearchString) >0) {
  25.            
  26.             // Now we have the string the user entered, we want to
  27.             // be able to use this to search in our database
  28.             // so we use the percentage as the wildcare and use a variable
  29.             // in the query.
  30.            
  31.             $query = $db->query("SELECT *
  32.                                  FROM TW_38_TRIBE
  33.                                  WHERE name
  34.                                  LIKE '$mysearchString%'
  35.                                  LIMIT 10"); // limits our results list to 10.
  36.            
  37.            
  38.             if($query) {
  39.                
  40.                 // so while there are results from the query
  41.                 // we loop through the results and fill out our list items
  42.                
  43.                 while ($result = $query ->fetch_object()) {
  44.                    
  45.                     // create a list item, but also listen for the user clicking
  46.                     // the result so we can fill the text box.
  47.                     echo '<li onClick="fill(\''.$result->product_title.'\');">'.$result->product_title.'</li>';
  48.                 }
  49.             } else {
  50.                 echo 'ERROR: There was a problem with the query.';
  51.             }
  52.         } else {
  53.             // Dont do anything.
  54.         }
  55.     } else {
  56.         echo 'Access denied.';
  57.     }
  58. }
  59. ?>
RAW Paste Data
Top