-
Notifications
You must be signed in to change notification settings - Fork 5
/
livesearch.php
36 lines (29 loc) · 1.19 KB
/
livesearch.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
<?php
require('config.php');
if(isset($_REQUEST["term"])){
$key = $_GET['term'];
$sql = "SELECT * FROM prof WHERE (fname LIKE '%{$key}%') OR (lname LIKE '%{$key}%') OR (email LIKE '%{$key}%') OR (web LIKE '%{$key}%') OR (aoi LIKE '%{$key}%')";
if($stmt = mysqli_prepare($db, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_term);
// Set parameters
$param_term = $_REQUEST["term"] . '%';
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
// Check number of rows in the result set
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo "<option>" . $row["fname"] . " " . $row["lname"] . "</option>";
}
} else{
echo "<option>No matches found</option>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
}
}
// Close statement
mysqli_stmt_close($stmt);
}
?>