Php,Sql查询不会让我传入变量,我不断得到一个空数组

时间:2016-09-26 03:10:02

标签: javascript php mysql html5

所以我尝试对我的数据库运行Select查询,但是当我传入预定义的变量时,查询将不起作用。但它只有当我在For Example'username'中明确输入它时才有用,但不会让我传入变量,例如'$ username'

所以我的角度文件中有一个函数,它将信息发布到我的php文件中。

这是我的php文件:

<?php

require "loginConnect.php";

if($conn) 
{

    $gotIt = json_decode(file_get_contents('php://input'));

    $username = mysqli_real_escape_string($conn, $gotIt->{"username"});
    $password = mysqli_real_escape_string($conn, $gotIt->{"password"});    


    $myquery = "SELECT Email, Firstname, Lastname, Username, Password, ConfirmPassword FROM Myusers WHERE Username = '$username'";

    // creating var to store the server's results 
    // passing in $conn for connection and $myQuery
    $request = mysqli_query($conn, $myquery); 

    if ($request)
    {
        echo "the request was made successfully";
    }
    else
    {
        echo "the request failed";
    }

    // declaring an array to store the results objects in 
    $data = array();

    // using the foreach loop to loop thu object in results 
    foreach ($request as $i) {
        $data[] = $i;
    }    
    // closing the connection and display the data 
    mysqli_close($conn);

    echo json_encode($data);

}
else //otherwise connection failed come here
{
    echo "sorry bad connection";
}


?>

所以当我在我的查询中传入$ username变量时,我甚至没有想到我应该得到什么,但当我输入像'theblackmamba'这样的用户名时,得到我想要的东西。即使变量容器具有相同的字符串,该变量也无法正常工作。请帮助我超级STUCK!

0 个答案:

没有答案