In this post, We have shared post a jquery autocomplete search using PHP MySQL and ajax. jquery and Ajax are the best part of the in web development. so in this post, we will make the jquery autocomplete search using PHP MySQL and Ajax.

so basically. We need to create a database and make the configuration PHP with MySQL. We will create an index.php file and this file in We will use the bootstrap and textbox. When visitor type in the textbox then We will use the keyup event of the jquery. If search value does not blank then ajax call to search.php file and that file connect with MySQL, It will search the data in the database using the "like where clause". If getting the searching related data then return the JSON formate data otherwise return the empty data.

Create a index.php file

<!DOCTYPE html>
<html lang="en">
  <title>jquery autocomplete search using php mysql and ajax</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
    ul{	list-style: none; padding: 0px;	width: 100%; padding-right: 5%;position: absolute;margin: 0; }
    ul li{ background:#D3DCE3;padding: 4px;margin-bottom: 1px;}
    ul li:nth-child(even){ background:#E5E5E5; color: white; }
    ul li:hover{ cursor: pointer; }
<script type="text/javascript">
                var search = $(this).val();
                if(search != ""){
                        url: 'search.php',
                        type: 'post',
                        data: {search:search},
                        dataType: 'json',
                            var len = response.length;
                            for( var i = 0; i<len; i++){
                                $("ul").append("<li value='"+response[i]['id']+"'>"+response[i]['name']+"</li>");

<div class="container auto">
    <div class="row" style="margin-bottom:10px;">
        <div class="col-lg-12"><h2 style="text-align:center;">jquery autocomplete search using php mysql and ajax</h2></div>
    <div class="form-group row">
        <div class="col-lg-3">&nbsp;</div>
        <div class="col-lg-6">
    		<label for="txtSearch">Enter Name:</label>
    		<input type="text" class="form-control" id="txtSearch" name="txtSearch">
	<div class="col-lg-3">&nbsp;</div>

Create a search.php file

	 $conn = mysqli_connect($hostname,$username,$password,$database);

    $searchText = $_POST['search'];
		$sql = "SELECT id,name FROM user where name like '%".$searchText."%' order by name asc limit 5";
		$result = mysqli_query($conn,$sql);
		$search_arr = array();

		while($row = mysqli_fetch_array($result)){
			$search_arr[] = array("id" => $row['id'], "name" => $row['name']);

		echo json_encode($search_arr);


I have shared demo. So you can click on Button and show the demo.

Show Demo

Connect With Facebook