I'm trying to populate an input field, using PHP/MySQL, with the Drew Wilson's jQuery Autosuggest plugin found here: http://tips4php.net/2010/09/ajax-autocomplete-with-jquery-and-php/
I get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 21
Here is my code:
$con = mysql_connect("localhost","username","password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$counter='0';
echo "{";
echo "query:'$query',";
echo "suggestions:[";
$res = mysql_query("SELECT airport, code FROM iata_airport_codes where name like '$query%' ORDER BY airport desc");
while($row = mysql_fetch_array($res)) {
$counter++;
if ($counter > 1) {
echo ",";
}
$airport=$row["airport"];
$code=$row["code"];
echo "'$airport', ('$code')";
}
echo "],}";
mysql_close($con);
What am I missing here? Can't see what I'm doing wrong.
Thanks in advance!
$query, also look up SQL injection and escaping inputs.