-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
56 lines (42 loc) · 1.28 KB
/
Copy pathsearch.php
File metadata and controls
56 lines (42 loc) · 1.28 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
<?php
$username = "root";
$password = "afif";
$database = "signzy";
$fname = "";
$lname = "";
if(isset($_REQUEST['fname'])) $fname = $_REQUEST['fname'];
if(isset($_REQUEST['lname'])) $lname = $_REQUEST['lname'];
if(strlen($fname)>=3 && strlen($lname)>=3){
$query = "SELECT * from all_names where fname like '%$fname%' AND lname like '%$lname%' limit 5";
}
// echo $fname.PHP_EOL;
// echo $lname.PHP_EOL;
else if(strlen($fname)>=3)
{
$query = "SELECT * from all_names where fname like '%$fname%' limit 5";
}
else if(strlen($lname)>=3)
{
$query="SELECT * from all_names where lname like '%$lname%' limit 5 ";
}
//echo $query.PHP_EOL;
// $query = "SELECT * from all_names WHERE fname LIKE '%Ind%' limit 5";
if(is_null($query)){
echoJSON(array("Response" => "Invalid parameters received."));
} else {
$con = mysqli_connect('localhost',$username,$password,$database) or die( "Unable to select database");
mysqli_set_charset($con, "utf8");
$response = array();
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
array_push($response, $row);
}
echoJSON(array('data' => $response));
}
function echoJSON($array) {
header('Content-type: Application/json; charset=UTF-8');
echo json_encode($array, JSON_PRETTY_PRINT);
}
mysqli_close($con);
?>