-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoSuggest.php
More file actions
27 lines (25 loc) · 935 Bytes
/
autoSuggest.php
File metadata and controls
27 lines (25 loc) · 935 Bytes
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
<?php
$db = new mysqli('DB_HOST', 'USERNAME', 'PASSWORD', 'DATABASE_NAME');
if (!$db) {
echo 'Database connection is not found.';
} else {
if (isset($_POST['q'])) {
$q = $db->real_escape_string($_POST['q']);
if (strlen($q) > 0) {
$query = $db->query("SELECT country FROM countries WHERE country LIKE '$q%' LIMIT 12");
if ($query) {
echo '<ul>';
while ($result = $query->fetch_object()) {
echo '<li onClick="fill(\''.addslashes($result->country).'\');">'.$result->country.'</li>';
}
echo '</ul>';
} else {
echo 'OOPS, There is a problem :(';
}
} else {
// do nothing
}
} else {
echo 'No direct access to this script!';
}
}