使用jquery进行即时搜索

时间:2016-03-03 20:16:38

标签: javascript php jquery

<form method="post" action="search.php">
Start searching: <input id="search" type="text" size="30" >
<div id="search_results"></div>

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="search.js"></script>
</id>
</form>

<?php
$searchname=$_POST["search"];
$connection = mysqli_connect("localhost","landryr","landryr","landryr");
 // Check connection
  if (mysqli_connect_errno())
  {
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$titles = mysqli_query($connection,"select * from actor where <mainactorID> LIKE '%$searchname%'");
while($row = mysqli_fetch_assoc($titles)) {
    $result[] = $row['mainactorID'];
}
?>

为什么ssearchname不被识别为变量?我唯一的问题是 “未定义的索引:在第3行的C:\ wamp \ www \ search.php中搜索”。请帮助。

1 个答案:

答案 0 :(得分:0)

您需要使用

<input id="search" name="search" type="text" size="30" >

看看这里:HTML Input Name Vs ID