user580950 user580950 - 1 year ago 191
SQL Question

Autocomplete doesnt work - PHP - Mysql - jQuery

When I type anything in the text box it doesn't display anything.
The search.php shows all the records if I hardcode


Probably it is something in the jQuery I am missing.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<link rel="stylesheet" href="//">
<script src="//"></script>
<script src="//"></script>
$(function() {
$( "#skills" ).autocomplete({
source: 'search.php'

<div class="ui-widget">
<label for="skills">skills: </label>
<input id="skills">

MY PHP (search.php) page is:

//get search term
$searchTerm = $_GET['term'];

//get matched data from skills table
$query = $db->query("SELECT * FROM skills WHERE skill LIKE '%".$searchTerm."%' ORDER BY skill ASC");
while ($row = $query->fetch_assoc()) {
$data[] = $row['skill'];

//return json data
echo json_encode($data);


["A A EDU","A T Still","A.B.I. ","Aani", "Zane"]

Chrome Debug

enter image description here

Answer Source

I can´t see the send params (data) to you server call.

like this (but i haven´t right if this work):

$(function() {
   $( "#skills" ).autocomplete({
      source: 'search.php',
      data: { 
         'term' : $('#skills').val()
      type: "GET"

I prefer use a plugin to do this, in the method AJAX is possible set the results to list in field. like this:

    lookup: function (query, done) {
            url: "form.php",
            dataType: "json",
            data: { 
                    term     : query 
            type: "GET", //you can change to POST if u need
            success: function( response ){
                var result = {
                    suggestions: response.results
            error: function(XMLHttpRequest, textStatus, errorThrown) { 
    onSelect: function (suggestion) {
        id_ofselected =; //set a var with selected object

In the Php Side u have a code like this:

$digits = $_GET['term'];

$query = $db->query(SELECT name AS `value`, id AS `data` 
          FROM table 
          WHERE name LIKE '$digits%'");

while ($row = $query->fetch_assoc()) {
    $data[] = $row['skill'];

    echo json_encode(array( 'results' => $cons ));
    echo json_encode(array( 'results' => array());  

I use Autocomplete Jquery plugin. See [a link] (!