私はPHP、MySQL、およびAJAXを使用してライブ検索を実行しようとしています。私は間違っているとは思わない。私のデータベースはphpMyAdminでホストされています。データベース名はInfoで、アクセスしようとしているテーブルは名前です。MySQL、PHP、およびAJAXによるライブ検索は機能していません
のindex.php index.phpの
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
#here
{
width:400px;
height:300px;
border: 1px solid grey;
display:none;
}
#here a{
display:block;
width:98%;
padding:1%;
font-size:20px;
border-bottom:1px solid grey;
}
</style>
<body>
<script src=jq.js></script>
<script src="jq.js">
$(document).ready(function(e)
{
$("search").keyup(function()
{
$("#here").show();
var x = $(this).val();
$.ajax(
{
type:'GET',
url:'fetch.php',
data: 'q='+x,
success:function(data)
{
$("#here").html(data);
}
,
});
});
});
</script>
<h1>Live Search</h1>
<input type="search" name="search" id="search">
<div id="here">
</div>
</body>
</html>
Fetch.php
<?php
if(!empty($_GET['q']))
{
include 'connect.php';
$q=$_GET['q'];
$query = "select * from names where names like '%$q%';";
while($output=mysqli_fetch_assoc($result))
{
echo '<a>'.$output['names'].'</a>';
}
$query = "select * from names";
}
あり
fetch.php
?>
<?php
$host="localhost";
$user="andremac96";
$password="";
$db="Info";
$conn = mysqli_connect($host,$user,$password,$db);
?>
[Little Bobby](http://bobby-tables.com/)は[あなたのスクリプトはSQLインジェクション攻撃の危険にさらされています。](http://stackoverflow.com/questions/60174/how-can-i) -prevent-sql-injection-in-php)[MySQLi](http://php.net/manual/en/mysqli)の[prepared](http://en.wikipedia.org/wiki/Prepared_statement)ステートメントについて学んでください。 .quickstart.prepared-statements.php)。 [文字列をエスケープする](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)でも安全ではありません! –
ブラウザのコンソールやエラーログにエラーが表示されていませんか? –
直接使用するとfetch.phpが正しいデータを出力していることを確認できますか? –