forked from sneha2245/online-chatting-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchbar.php
61 lines (56 loc) · 2.48 KB
/
searchbar.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
session_start();
if(isset($_REQUEST["term"])){
$servername="localhost";
$username="root";
$password="";
$dbName="chatting-system";
$port="3308";
$conn = mysqli_connect($servername, $username, $password, $dbName, $port);
if(!$conn){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "select * from users where uname like ?";
if($stmt = mysqli_prepare($conn, $sql)){
mysqli_stmt_bind_param($stmt,"s",$param_term);
$param_term = $_REQUEST["term"] . '%';
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
if($_SESSION["userName"]!=$row["uname"]){
$row++;
if($row['gender']=="M"){
echo '<a href="chat.php?id= '.$row["id"].'" header("Location: main.php");>'.
'<div id="echoDiv" style="width: 380px !important;margin-bottom: 5px;margin-top: 10px;" class="echoDiv border-avaliable">' .
'<div style="border-radius:50%;height:50px;width:50px;float:left">' .
'<img style="border-radius:100%;height:50px;width:50px;margin: auto;"src="images/male.png" alt=" Male"/> ' .
'</div>' .
'<div style="width: 270px !important;" class="div-echoDiv">' . $row["uname"] . '</div>' .
'<div style="width: 270px !important; " class="div-echoDiv margin">' . $row["email"] . '</div>'.
'</div>'.
'</a>';
}else {
echo '<a href="chat.php?id= '.$row["id"].'" header("Location: main.php");>'.
'<div id="echoDiv" style="width: 380px !important;margin-bottom: 5px;margin-top: 10px;" class="echoDiv border-avaliable">' .
'<div style="border-radius:50%;height:50px;width:50px;float:left">' .
'<img style="border-radius:100%;height:50px;width:50px;margin: auto;"src="images/female.png" alt="Female"/> ' .
'</div>' .
'<div style="width: 270px !important;" class="div-echoDiv">' . $row["uname"] . '</div>' .
'<div style="width: 270px !important; " class="div-echoDiv margin">' . $row["email"] . '</div>'.
'</div>'.
'</a>';
}
}
}$row++;
}else{
echo '<h5 style="margin-top: 10px;">No matches found</h5>';
}
}else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
?>