Jump to content


Help needed for autocomplete textbox

jquery php textbox autocomplete mysql

  • Please log in to reply
2 replies to this topic

#1 masnobi

  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 15 April 2013 - 05:45 AM

Hi all,

I am making a flight search engine where i am trying to create a autocomplete textbox. I mean when a user starts typing in the textbox, it will show all related data from my database table.

I am new to programming and therefore I have adopt a code from online but it doesn't work, I don't know why. Can anyone please help? 

If you know any other easy way of doing it, please tell me also


This is my Javascript code:

<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>

<script type="text/javascript">
$().ready(function() {
$("#depAirport").autocomplete("autoCompleteMain.php", {
width: 260,
matchContains: true,
//mustMatch: true,
//minChars: 0,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false

This is my html:

            <label for="depAirport">Deperture airport</label>
            <input type="text" id="depAirport" name="depAirport" placeholder="Type destination airport" required autofocus>

and this is my php:

$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="airline_database"; // Database name

$con = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db_name, $con) or die(mysql_error());

$q = strtolower($_GET["q"]);
if (!$q) return;

$sql = "select DISTINCT departure_airport as departure_airport from depAirport where departure_airport LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['departure_airport'];
echo "$cname\n";


#2 jugesh

  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 23 April 2013 - 07:50 AM

check for connection variables.. It seems they are wrong

#3 jugesh

  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 23 April 2013 - 07:51 AM

instead of name (output) try to print query and run it in phpmyadmin interface you will come to know if there is any error

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users