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

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题