Home » Autocomplete Search Box / textbox in PHP MySQL

Autocomplete Search Box / textbox in PHP MySQL

Today, We want to share with you autocomplete search box in php mysql.In this post we will show you global search in php mysql with examples, hear for autocomplete textbox with multiple values using jquery, php and mysql we will give you demo and example for implement.In this post, we will learn about How to create an suggestions search box in jQuery and PHP? with an example.

php autocomplete textbox from database example

There are the Following The simple About jquery autocomplete ajax json php Full Information With Example and source code.

Read Also:  Autocomplete Textbox using jQuery, PHP and MySQLi

As I will cover this Post with live Working example to develop php mysql ajax search autocomplete, so the autofill html form from database is used for this example is following below.

Step 1: Create a Database Connection File

    $dbname = "shops";
          die('Could not Connect MySql Server:' .mysql_error());

Step 2: Create an Autocomplete search form

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>suggestions Search Box in PHP MySQL - Pakainfo.com</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" />
  <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
  <!-- Bootstrap Css -->
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
  <div class="row">
     <h2>Search Here</h2>
     <input type="text" name="search" id="search" placeholder="search here...." class="form-control">  
<script type="text/javascript">
  $(function() {
     $( "#search" ).autocomplete({
       source: 'ajax-db-search.php',

Step 3: Create a PHP Script for Search to DB

require_once "db.php";
if (isset($_GET['term'])) {
   $query = "SELECT * FROM products WHERE name LIKE '{$_GET['term']}%' LIMIT 25";
    $result = mysqli_query($conn, $query);
    if (mysqli_num_rows($result) > 0) {
     while ($product = mysqli_fetch_array($result)) {
      $results[] = $product['name'];
    } else {
      $results = array();
    //return json results
    echo json_encode($results);

how to implement an autocomplete search box or textbox in PHP MySQL with jQuery Ajax from the database table using jQuery UI Autocomplete JS.

Read Also:  PHP MySQL ajax Autocomplete Live Search Box in jQuery

I hope you get an idea about autocomplete search box in php mysql.
I would like to have feedback on my infinityknow.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:  Angular check ngIf Array is Empty/isset/Null
  2. Read Also:  PHP Autocomplete Input tags with Dynamic Data using jquery Ajax
  3. Read Also:  Laravel 6 Show images from storage folder
  4. Read Also:  Javascript Autocomplete Address Using PHP With Demo
  5. Read Also:  Ajax Autocomplete Live Search Suggestion using PHP MySQL
  6. Read Also:  Advanced Pagination with PHP, MySQL and jQuery Demo
  7. Read Also:  Login Signup with Laravel
  8. Read Also:  authentication login with username or email in laravel
  9. Read Also:  PHP Autocomplete Textbox using jQuery Example
  10. Read Also:  Laravel AJAX Live Autocomplete Search from Database

Leave a Comment

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