Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryautosuggest和PHP/MySQL问题_Php_Jquery_Mysql_Jquery Autocomplete_Autosuggest - Fatal编程技术网

jqueryautosuggest和PHP/MySQL问题

jqueryautosuggest和PHP/MySQL问题,php,jquery,mysql,jquery-autocomplete,autosuggest,Php,Jquery,Mysql,Jquery Autocomplete,Autosuggest,我正在尝试使用PHP/MySQL填充一个输入字段,这里有Drew Wilson的jQuery Autosuggest插件: 我收到以下错误:警告:mysql\u fetch\u array():提供的参数在第21行不是有效的mysql结果资源 这是我的密码: $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }

我正在尝试使用PHP/MySQL填充一个输入字段,这里有Drew Wilson的jQuery Autosuggest插件:

我收到以下错误:警告:mysql\u fetch\u array():提供的参数在第21行不是有效的mysql结果资源

这是我的密码:

$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);
我错过了什么?看不出我做错了什么


提前谢谢

警告:mysql\u fetch\u array():第21行提供的参数不是有效的mysql结果资源

始终意味着SQL查询中存在错误。请尝试打印myqsl_error()内容


您应该使用
json\u encode()
不要自己打印json。

警告:mysql\u fetch\u array():第21行提供的参数不是有效的mysql结果资源

始终意味着SQL查询中存在错误。请尝试打印myqsl_error()内容


您应该使用
json\u encode()
而不是自己打印json。

显示错误:

 mysql_query("SELECT airport, code FROM iata_airport_codes where name like '$query%' ORDER BY airport desc") or die(mysql_error());

它显示一个错误:

 mysql_query("SELECT airport, code FROM iata_airport_codes where name like '$query%' ORDER BY airport desc") or die(mysql_error());

$query
的内容是什么,还可以查找SQL注入和转义输入。
$query
的内容是什么,还可以查找SQL注入和转义输入。