http请求获取url变量

时间:2016-05-02 20:44:58

标签: php ajax xmlhttprequest httprequest

您好我尝试使用http请求获取php查询的结果,并在php中使用$GET[]获取它。我检查了我的数据库应该有一行匹配。是什么原因造成的?

我收到的PHP错误是:

  

警告: mysqli_fetch_array()要求参数1为mysqli_result,布尔值为...

var text= $("#username").val();  
    if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("resultt").innerHTML = xmlhttp.responseText;

            }
        };
        xmlhttp.open("GET","http://website/project/readusern.php?username="+text,true);
        xmlhttp.send();


        }

readusern.php

    $searchuser = $_GET["username"];
    $myname = $_COOKIE["userid"];
    $con=mysqli_connect('localhost','username','pw','db');
    if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }



    $data = "SELECT * FROM user 
    WHERE username = $searchuser
    AND id != $myname
     ORDER BY id ASC";
    $result = mysqli_query($con, $data);

    while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){

//echo results

    }

0 个答案:

没有答案