Jump to content

Help needed for autocomplete textbox


masnobi

Recommended Posts

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
});
});
</script>

This is my html:

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

and this is my php:

<?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";
}
?>

PLEASE HELP ASAP

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.