duancenxiao0482 2013-09-24 14:43
浏览 52

自动完成,MYSQL,PHP

I have been trying to implement this and the code does not seem to be working. I want auto-complete to go with name from database.Looks like I am connecting to database fine but auto-complete is not working.
Here it is.

Form jquery

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
 <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />

    <script type="text/javascript">
            $(document).ready(function(){
                $("#name").autocomplete({
                    source:'search.php',
                    minLength:1
                });
            });
    </script>

Here is form

<form action="search.php" method="GET">
Last Name : <input type="text" id="First_Name" name="query" />
<input type="submit" value="Search" />
</form>

Here is search.php

<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="ambassador"; // 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 First_Name as First_Name from First_Name where First_Name      LIKE     '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['First_Name'];
echo "$cname
";
}
?>
  • 写回答

1条回答 默认 最新

  • douhuan6157 2013-09-24 16:20
    关注

    I would say that you have the wrong table name, unless it really is "First_Name"...

    But let me ask you: what happens if someone enters the value " '; SHOW TABLES"?

    http://www.php.net/manual/en/security.database.sql-injection.php

    评论

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作