-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_users.php
More file actions
57 lines (46 loc) · 1.61 KB
/
search_users.php
File metadata and controls
57 lines (46 loc) · 1.61 KB
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
<?php
require 'db.php';
if(isset($_GET['query'])){
$query = $conn->real_escape_string($_GET['query']);
$status= isset($_GET['status'])? $conn->real_escape_string($_GET['status']):'';
$type= isset($_GET['type'])? $conn->real_escape_string($_GET['type']):'';
$sql = "SELECT * FROM users WHERE (Name LIKE '%$query%' OR Email LIKE '%$query%' OR Phone LIKE '%$query%')";
if($status !== ''){
$status_value= ($status=='Active')?1:0;
$sql.= "AND status = $status_value";
}
if($type !== ''){
$type_value= ($type=='Admin')?1:0;
$sql.= "AND Type = $type_value";
}
$result=$conn->query($sql);
$users=[];
if($result->num_rows>0){
while($row=$result->fetch_assoc())
{
$users[]=$row;
}
}
header('Content-Type: application/json');
echo json_encode($users);
}
?>
<?php
// require 'db.php';
// if (isset($_GET['query'])) {
// $query = $_GET['query'];
// $searchQuery = '%' . $conn->real_escape_string($query) . '%'; // Safely escape the input
// $stmt = $conn->prepare("SELECT * FROM users WHERE Name LIKE ?");
// $stmt->bind_param('s', $searchQuery);
// $stmt->execute();
// $result = $stmt->get_result();
// $users = [];
// if ($result->num_rows > 0) {
// while ($row = $result->fetch_assoc()) {
// $users[] = $row;
// }
// }
// header('Content-Type: application/json'); // Set the correct content type
// echo json_encode($users);
// }
?>