Home » PHP Ajax Autocomplete Search from Database Example

PHP Ajax Autocomplete Search from Database Example

Today, We want to share with you PHP Ajax Autocomplete Search from Database Example.In this post we will show you MySQL Database Live Search with PHP and AJAX, hear for jQuery Autocomplete Search using PHP, MySQL and Ajax we will give you demo and example for implement.In this post, we will learn about Autocomplete Textbox using jQuery, PHP and MySQL with an example.

PHP Ajax Autocomplete Search from Database Example

There are the Following The simple About PHP Ajax Autocomplete Search from Database Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Ajax Search Box in PHP and MySQL, so Creating Autocomplete for City Search Using PHP and MySQL Database for this example is following below.

Read Also:  Top 40 Laravel Interview Questions

Step 1: Create members table

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`),
  UNIQUE KEY `members_email_unique` (`email`)

Step 2: Create index.php file

<!DOCTYPE html>
	<meta charset="utf-8">
	<title>pakainfo.com - </title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
	<style type="text/css">
			display: none;
		.list-span3-list a{
			text-decoration: none !important;
		.list-span3 li{
			cursor: pointer;
			padding: 4px 0px;
			list-style-type: none;
    		background: #d4e8d7;
		.list-span3 li:hover{
			color: white;
			background-color: #3d3d3d;
<div class="container">
	<h1 class="text-center pakainfo">Auto Complete Search using jQuery</h1>
	<div class="row justify-content-center pakainfo">
		<div class="col-sm-6">
			<form id="pakainfoFrm" method="POST" action="">
				<div class="input-span3 input-span3-lg">
				  	<input type="text" id="searchquery" name="searchquery" class="form-control" placeholder="Eneter Your Search Name" aria-describedby="basic-addon2">
			<ul class="list-span3" id="pakainfo_find"></ul>
	<a href="https://www.pakainfo.com/" target="_blank" alt="pakainfo" title="pakainfo">Free Download Example - Pakainfo.com</a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
	//jQuery Autocomplete search using Serever side Get Data PHP, MySQLi, Ajax and jQuery
		//here HTML Form to generate suggestion on keyup
			var form = $('#pakainfoFrm').serialize();
				type: 'POST',
				url: 'get_membersList.php',
				data: form,
				dataType: 'json',
				success: function(response){
		//jQuery fill the input
		$(document).on('click', '.list-span3-list', function(e){
			var memberFname = $(this).data('memberFname');

Step 3: Create get_membersList.php file

		$conn = new mysqli('localhost', 'root', 'root', 'atmiya_25');
		$datar_response = array('error' => false, 'data' => '');
		$searchquery = $_POST['searchquery'];
			$datar_response['error'] = true;
			$sql = "SELECT * FROM members WHERE name LIKE '%$searchquery%'";
			$sqlquery = $conn->query($sql);
			if($sqlquery->num_rows > 0){
				while($memberData = $sqlquery->fetch_assoc()){
					$datar_response['data'] .= "
						<li class='list-span3-list' data-memberFname='".$memberData['name']." ".$memberData['lastname']."'>".$memberData['name']." ".$memberData['lastname']."</li>
				$datar_response['data'] = "
					<li class='list-span3-list'>No Any found data matches Members Records</li>
		echo json_encode($datar_response);

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Ajax Autocomplete Live Search Suggestion using PHP MySQL


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Ajax Autocomplete Search from Database Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Bootstrap Modal popup multiple File Upload using AJAX
  2. Read Also:  Draw Responsive Google Charts Example Tutorial From Scratch
  3. Read Also:  vue router change route programmatically
  4. Read Also:  Laravel Toggle Switch with Ajax Update Database
  5. Read Also:  CodeIgniter Beginners Tutorial Step by Step
  6. Read Also:  JavaScript Top 5 Most useful JSON Example
  7. Read Also:  PHP Creating Dynamic Directory (Folder) Example
  8. Read Also:  Laravel create text file for json file and file download
  9. Read Also:  Dynamic Autocomplete Textbox in jQuery Ajax
  10. Read Also:  VueJS setTimeout() Function Examples

Leave a Comment

Your email address will not be published. Required fields are marked *