I am attempting to create a searchbox using php and AJAX. However, when I type a name already in the database into searchbox, no suggestion appear. Nothing happens.
I have tested the php and seems to be working. What am I missing?
Code update with PDO
require_once('connect_pdo.php');
$searchTerm = $_GET['term'];
$stmtus = $conn->prepare("SELECT * FROM `Schools` WHERE `School` LIKE :School");
$stmtus->bindValue(':School', '%' . $searchTerm . '%');
$searchTerm = $_POST['school'];;
$stmtus -> execute();
while ($result = $stmtus->fetch(PDO::FETCH_ASSOC)) {
$school = $result['School'];
}
echo json_encode($school);
AJAX
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
<script type="text/javascript">
$(document).ready(function(){
$("#school").autocomplete({
source:'schoolfind.php',
minLength:3
});
});
</script>
HTML
<label>What school does the child attend<input type="text" name="school" id="school" /></label>