Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. #Start Search Page
  2. <?php
  3.     include("scripts/database_connection.php");
  4.     include("scripts/functions.php");
  5.     start_secure_session();
  6.     if(is_user_logged_in($sqli_con)) {
  7.        
  8.     } else {
  9.         header("Location: index.php");
  10.     }
  11. ?>
  12. <!DOCTYPE HTML>
  13. <html>
  14.    
  15.     <head>
  16.         <meta charset="UTF-8" />
  17.         <title>Source | Search</title>
  18.         <link rel="stylesheet" type="text/css" href="style/reset.css" />
  19.         <link rel="stylesheet" type="text/css" href="style/main.css" />
  20.         <script>
  21.             function search(query) {
  22.                 if(query.length > 0) {
  23.                     if(window.XMLHttpRequest) {
  24.                         xmlhttp = new XMLHttpRequest();
  25.                     } else {
  26.                         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  27.                     }
  28.  
  29.                     xmlhttp.onreadystatechange = function() {
  30.                         if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  31.                             document.getElementById("search_results").innerHTML = xmlhttp.responseText;
  32.                         }
  33.                     }
  34.  
  35.                     xmlhttp.open("GET", "scripts/search.php?query=" + query, true);
  36.                     xmlhttp.send();
  37.                 } else {
  38.                     document.getElementById("search_results").innerHTML = "";
  39.                     return;
  40.                 }
  41.             }
  42.         </script>
  43.     </head>
  44.  
  45.     <body>
  46.         <?php include("scripts/includes/header.inc.php"); ?>
  47.  
  48.         <div id="site_content">
  49.             <div id="search_bar">
  50.                 <form>
  51.                     <input type="text" name="search_query" onkeyup="search(this.value);" placeholder="Search for people..."/>
  52.                 </form>
  53.                 <div id="search_results">
  54.  
  55.                 </div>
  56.             </div>
  57.         </div>
  58.  
  59.         <?php include("scripts/includes/footer.inc.php"); ?>
  60.     </body>
  61.  
  62. </html>
  63.  
  64. #End Search Page
  65.  
  66. #Start Search Script
  67. <?php
  68.     include("database_connection.php");
  69.  
  70.     $search_query = mysqli_escape_string($sqli_con, strip_tags($_GET['query']));
  71.    
  72.     if(strlen($search_query) > 0) {
  73.         $query = $sqli_con->query("SELECT id, username, avatar, first_name, last_name, country, gender, user_level FROM members WHERE username = '$search_query'");
  74.  
  75.         if($query->num_rows > 0) {
  76.             $row = $query->fetch_array(MYSQLI_NUM);
  77.             if($row[6] == 'm') {$row[6] = 'Male';} else {$row[6] = 'Female';}
  78.             if($row[7] == 'a') {$row[7] = 'Administrator';} else if($row[7] == 'm'){$row[7] = 'Moderator';} else {$row[7] = 'Regular';}
  79.             echo "<div id='search_result'>
  80.                     <a href='profile.php?id=". $row[0] ."'><img src='". $row[2] ."' /></a><a href='profile.php?id=".  $row[0] ."'>". $row[1] ."</a>
  81.                     <br /><p>". $row[3] ." ".  $row[4] ."</p><br />
  82.                     <p>".  $row[5] ."</p><br />
  83.                     <p>".  $row[6] ."</p><br />
  84.                     <p>".  $row[7] ."</p>
  85.                 </div>";
  86.         }
  87.  
  88.         $query->free();
  89.         $sqli_con->close();
  90.     }
  91.  
  92. ?>
  93. #End Search Script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement