-
Notifications
You must be signed in to change notification settings - Fork 4
/
search.php
44 lines (38 loc) · 1.45 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
ini_set('display_errors', '0'); //to stop showing unnecessary warnings and errors
$servername="127.0.0.1";
$database="axel";
$username="root";
$password="";
$conn=mysqli_connect($servername,$username,$password,$database);
if(!$conn)
{
die("Connection error: " . mysql_connect_errno());
header('location:error.php');
}
if(isset($_POST["query"]))
{
$output = '';
$searchtext = mysqli_escape_string($conn,$_POST["query"]);
$query = "SELECT * FROM users WHERE Name LIKE '%$searchtext%'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$userid = $row["userID"];
$username = $row["Name"];
$output .= '<div class="searchlistitem" onclick= "selectuser(\''.$userid.'\')">';
$output .= '<img class="sDP" src= "'.$row["DP"] . '" alt="avatar.png">';
/*$output .= '<img class="DP" src= "'."avatar.png". '" alt="defaultimgholder.png">';*/
$output .= '<span class="profile"><div class = "uname">' .$username.'</div>';
$output .= '<div class="utype">' .$row["userType"].'</div></span></div>';
}
}
else
{
$output .= '<div style="color:black;margin:15px 0px">No results found!</div>';
}
echo $output;
}
?>