Monday, 20 April 2015

Auto Complete Textbox in PHP

In this tutorial you will learn how a auto complete textbox using php. It so simple and easy.
here i will use the java script function for this task.

Auto Complete textbox in php
Auto Complete textbox in php

first of all you will create the two php files.

  1. index.php
  2. autocomplete.php

Step 1:

when you create the index.php file then open it and past the following code in it.


 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">  
 <html xmlns="">  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <title>Auto Complete textbox in php |</title>  
 <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />  
 <script type="text/javascript" src="jquery.js"></script>  
 <script type="text/javascript" src="jquery.autocomplete.js"></script>  
  $("#student").autocomplete("autocomplete.php", {  
           selectFirst: true  
   <input name="student" type="text" id="student" size="20" />  

Step 2:

Now open the autocomplete.php file which is already created, and past the following code in it.


      $mysql=mysql_connect('localhost','root','') or die("Database Error");  
      $db=mysql_select_db('test') or die("Database Error");  
      $sql="SELECT std_name FROM student_info WHERE std_name LIKE '%$my_data%' ORDER BY std_name";  
      $result = mysql_query($sql,$mysql);  
                echo $row['std_name']."\n";  

Now your auto complete textbox is ready for working. run your index.php file and use this functionality.

No comments:

Post a Comment