为什么我的PHP脚本没有从mysql数据库获取城市

时间:2016-06-15 01:40:48

标签: javascript php mysql

我做错了什么?我是新手,我的代码并没有从mysql数据库中提取城市。

function getXMLHTTP() { //fuction to return the xml http object
    var xmlhttp=false;  
    try{
        xmlhttp=new XMLHttpRequest();
    }
    catch(e)    {       
        try{            
            xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e){
            try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e1){
                xmlhttp=false;
            }
        }
    }

    return xmlhttp;
}


function getCity(state) {       

var strURL="get_city.php?state="+state;
var req = getXMLHTTP();

if (req) {
    req.onreadystatechange = function() {
    if (req.readyState == 4 && req.status==200) {
        document.getElementById("citydiv").innerHTML=req.responseText;
            }
        }
    req.open("GET","get_city.php?state="+stateL,true);
    req.send(null);
}
}
<div class="row">
        <span class="small-6 columns" style="inline">
            <label>Location</label>
            <select name="state" method="GET" id="state"     onChange="getCity(this.value)">
                        <option value="0">Select State</option>
                        <option value=1>Alabama</option>
                        <option value=2>Alaska</option>
                        <option value="3">Arizona</option>
                        <option value=AR>Arkansas</option>
                        <option value=CA>California</option>

                        <option value="CO">Colorado</option>
                        <option value="CT">Connecticut</option>
                        <option value="DE">Delaware</option>
                        <option value="DC">District of Columbia</option>
                        <option value="FL">Florida</option>

                        <option value="GA">Georgia</option>
                        <option value="HI">Hawaii</option>
                        <option value="ID">Idaho</option>
                        <option value="IL">Illinois</option>
                        <option value="IN">Indiana</option>

                        <option value="IA">Iowa</option>
                        <option value="KS">Kansas</option>
                        <option value="KY">Kentucky</option>
                        <option value="LA">Louisiana</option>
                        <option value="ME">Maine</option>

                        <option value="MD">Maryland</option>
                        <option value="MA">Massachusetts</option>
                        <option value="MI">Michigan</option>
                        <option value="MN">Minnesota</option>
                        <option value="MS">Mississippi</option>

                        <option value="MO">Missouri</option>
                        <option value="MT">Montana</option>
                        <option value="NE">Nebraska</option>
                        <option value="NV">Nevada</option>
                        <option value="NH">New Hampshire</option>

                        <option value="NJ">New Jersey</option>
                        <option value="NM">New Mexico</option>
                        <option value="NY">New York</option>
                        <option value="NC">North Carolina</option>
                        <option value="ND">North Dakota</option>

                        <option value="OH">Ohio</option>
                        <option value="OK">Oklahoma</option>
                        <option value="OR">Oregon</option>
                        <option value="PA">Pennsylvania</option>
                        <option value="RI">Rhode Island</option>

                        <option value="SC">South Carolina</option>
                        <option value="SD">South Dakota</option>
                        <option value="TN">Tennessee</option>
                        <option value="TX">Texas</option>
                        <option value="UT">Utah</option>

                        <option value="VT">Vermont</option>
                        <option value="VA">Virginia</option>
                        <option value="WA">Washington</option>
                        <option value="WV">West Virginia</option>
                        <option value="WI">Wisconsin</option>

                        <option value="WY">Wyoming</option>
                </select></span>

        <span class="small-6 columns" style="inline">
            <select name="city" id="citydiv" >
                    <option value="">Select City</option>
        </select></span>
        </div>

我的php文件get_city:

<?php

$state_selected=strval($_GET['state']);
echo $state_selected;

$link=mysqli_connect("127.0.0.1","root","cw","locations");
if(mysqli_connect_errno()) {
    printf("connect failed: %s\n",mysqli_connect_error());
    exit();
}

$query="select city from cities where state_code= '".$state_selected."'";

$rs=mysqli_query($link,$query);
?>

<select name="city" id="citydiv" onchange="populate_utility_menu(this.value)">

<?php

while($row=mysqli_fetch_array($rs)) {
    echo "<option value=>".$row['city'];    
    echo "</option>";
}
?>
</select>

我意识到我的一些选项值与我想传递的两个字符串不同,但我只是检查是否存在问题。我甚至不确定如何研究除谷歌检查员和apache2 error.log文件之外的更多内容,这个文件位于下方,看起来可能是php并没有加载mysql文件但是我是如何检查或指引它到正确的路径是无能为力的。请帮助并记住我是非常新的。

apache2 error.log

  

PHP警告:PHP启动:无法加载动态库&#39; /usr/lib/php5/20121212/msql.so' - /usr/lib/php5/20121212/msql.so:无法打开共享对象文件:第0行的“未知”中没有此类文件或目录

     

[Tue Jun 14 17:48:47.600742 2016] [mpm_prefork:notice] [pid 13981] AH00163:Apache / 2.4.7(Ubuntu)PHP / 5.5.9-1ubuntu4.14已配置 - 恢复正常操作

     

[Tue Jun 14 17:48:47.600928 2016] [core:notice] [pid 13981] AH00094:命令行:&#39; / usr / sbin / apache2&#39;

1 个答案:

答案 0 :(得分:0)

您是否升级了PHP版本?可能是您的配置文件仍指向旧的位置路径。试试这个:

sudo apt-get install php5-mcrypt
sudo apt-get install php5-mysql