简体   繁体   English

自动完成,MYSQL,PHP

[英]Auto complete, 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 表单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 这是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\n";
}
?>

I would say that you have the wrong table name, unless it really is "First_Name"... 我会说您的表名错误,除非它确实是“ First_Name” ...

But let me ask you: what happens if someone enters the value " '; SHOW TABLES"? 但是让我问你:如果有人输入值“'; SHOW TABLES”,会发生什么?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM