Ok so i'm trying to do a live search using PHP, MySQL, and AJAX. I'm not to sure were i'm going wrong. My database is hosted on phpMyAdmin. The database name is Info and the table i'm trying to access is names.
My three pages are index.php connect.php and fetch.php Index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
#here
{
width:400px;
height:300px;
border: 1px solid grey;
display:none;
}
#here a{
display:block;
width:98%;
padding:1%;
font-size:20px;
border-bottom:1px solid grey;
}
</style>
<body>
<script src=jq.js></script>
<script src="jq.js">
$(document).ready(function(e)
{
$("search").keyup(function()
{
$("#here").show();
var x = $(this).val();
$.ajax(
{
type:'GET',
url:'fetch.php',
data: 'q='+x,
success:function(data)
{
$("#here").html(data);
}
,
});
});
});
</script>
<h1>Live Search</h1>
<input type="search" name="search" id="search">
<div id="here">
</div>
</body>
</html>
Fetch.php
<?php
if(!empty($_GET['q']))
{
include 'connect.php';
$q=$_GET['q'];
$query = "select * from names where names like '%$q%';";
while($output=mysqli_fetch_assoc($result))
{
echo '<a>'.$output['names'].'</a>';
}
$query = "select * from names";
}
fetch.php
?>
<?php
$host="localhost";
$user="andremac96";
$password="";
$db="Info";
$conn = mysqli_connect($host,$user,$password,$db);
?>