使用MySQL和PHP结果的jQuery自动完成不会显示

时间:2013-10-28 17:06:21

标签: php jquery mysql jquery-ui-autocomplete

我在jQuery中遇到插件问题它没有向我显示任何结果。我不在哪里弄错了?

那是我的newJob.php:

<form method="post" action="newJob.php">
<span>Customer Name:<input type="text" id="customerName" name="customerName"></span><br>
<input type="submit" name="submitJob" value="Create Job" >
</form>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/startDate.js"></script>
<script type="text/javascript">
  $(function() {
     //autocomplete
     $("#customerName").autocomplete({
       source: "searchCustomer.php",
       minLength: 1
     });                
  });
</script>

我的searchCustomer.php:

<?php
include('classes.php');

$obj = new CompanyDatabase;
$obj->connect_db();
$obj->select_db();

if (isset($_POST['customerName'])) {
$query = $_POST['customerName'];
$sql = mysql_query ("SELECT `Customer Name` FROM `job` WHERE `Customer Name` LIKE \"%".$query."%\"");
$array = array();
while ($row = mysql_fetch_assoc($sql)) {
    $array[] = $row['customerName'];
}
echo json_encode ($array); //Return the JSON Array
}
?>

它有什么问题吗?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我相信MySQL不允许列名和表名在名称之间包含空格。您确定使用的是正确的列名和表名吗?