使用jquery从运行mysql的php脚本返回信息

时间:2016-04-27 22:20:18

标签: javascript php jquery html mysql

我知道这个标题有点令人困惑,所以我会在这里尝试更好地解释。

我正在尝试创建一个用户输入票证的表单,并根据他们提供的服务将该票证分配给技术人员。我有3个文本字段,用户名,电子邮件,问题描述。下一个字段是选择字段。我通过运行一个php脚本来填充这个select字段,该脚本将查询所提供服务的数据库并返回结果。 像

这样的东西
<select name="service' id= "Service" onClick="showTechnican()">
<?php include "services_offered.php"?>
</select>

当用户点击其中一个服务时,我希望该表单查询我的services_offered表并返回在div中提供该服务的用户名。

<div id="techs"></div>

我正在使用jquery脚本来执行此操作

<script>
function showTechnician(){
var selectedValue = $("#Service").val();
if(selectedValue.length < 1){
    document.getElementById("techs").inner.HTML = "Please Select A Service Above";
    return;
}else{
    var url = "technicians.php?q="+selectedValue;
    $.get(url,function(data,status){
        document.getElementById("techs").innerHTML=data;
    });
}
  }

我还得到了为我查询数据库的脚本technicians.php

<select name= "tech">
<?php
$q = $GET['q'];
$conn = new mysqli("localhost", "proxy_user",
    "my*password","helpdesk");
if(mysqli_connect_errno()){
    echo'Unable to connect to database:'.
    mysqli_connect_error($conn);
}
    else{
        $query = "SELECT * FROM services WHERE Service_Descripton LIKE'%".$q.
        "%';";
        $result = mysqli_query($conn,$query);
        if(!$result){
            die("Invalid Query:" . mysqli_error($conn));
        }
            else{
                while($row = mysqli_fetch_array($result)){
                    echo"<option value= "."{$row['User_Name']}>"."{$row['Service_Description']}".
                    '</option><br/>';
                }
                mysqli_close($conn);
            }
    }
   ?>

我的问题是,当我点击提供的服务时,我的div只显示一个小空框。不确定为什么它没有返回任何东西。我在表格中有大量的测试数据。确保权限也是正确的。我检查了php_error_log,查询没有失败。我不知道如何解决这个问题。表单上的每个其他字段都将插入到数据库中。 我附上了这个问题的照片。在“可用的测试人员”下看到它只显示一个小盒子。

photo of the problem

1 个答案:

答案 0 :(得分:0)

I figured it out. I can't spell, had a spelling mistake in the output of my query. Fixed it and everything worked as it should.