-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautocomp2.php
50 lines (49 loc) · 1021 Bytes
/
autocomp2.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
<?php
$servername = "localhost";
$user = "root";
$password = "alva";
$dbname = "helphand";
// Create connection
$conn = new mysqli($servername, $user, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$q=$_GET['term'];
$d=$_GET['typee'];
$nn="username";
$data=array();
$s="select DISTINCT username from users where username LIKE'%$q%'";
if($d=="Email")
{
$s="select DISTINCT email from users where email LIKE'%$q%'";
$nn="email";
}
else if($d=="Username")
{
$s="select DISTINCT username from users where username LIKE'%$q%'";
$nn="username";
}
else
{
$result = $conn->query($s);
if ($result->num_rows!=0)
{
while($row = $result->fetch_assoc())
{
array_push($data,$row[$nn]);
}
}
$s="select DISTINCT email from users where email LIKE'%$q%'";
$nn="email";
}
$result = $conn->query($s);
if ($result->num_rows!=0)
{
while($row = $result->fetch_assoc())
{
array_push($data,$row[$nn]);
}
}
echo json_encode($data);
?>