我无法从angular php和mysql

时间:2017-04-26 10:03:18

标签: php mysql angular login

每次我尝试时,我的login.html如下所示,但在控制台中打印空值数组  它是index.html路由中的一个视图,一切正确,我的login.php如下所示

<?php
 header("Access-Control-Allow-Origin: *");
 header("Content-Type: text; charset=UTF-8");
        header("Access-Control-Allow-Methods: POST");
        header("Access-Control-Max-Age: 3600");
 header("Access-Control-Allow-Headers: Content-Type,    Access-Control-Allow-Headers, Authorization, X-Requested-With");
        // set up the connection variables
        $db_name  = 'news_to_angular';
        $hostname = '127.0.0.1';
        $username = 'root';
        $db_password = '';

$data = json_decode(file_get_contents("php://input"));
$da = json_decode(file_get_contents("php://input"));

/*$email="nasir@saiyed.com";
$pass="admin123";

*/

$email = mysql_real_escape_string($data->email);
$pass = mysql_real_escape_string($da->password);



        // connect to the database
        $dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $db_password);

        // a query get all the records from the users table
       /* $sql = 'SELECT email,password FROM users';*/

       $sql = 'SELECT email,password FROM users WHERE email = "'.$email.'" ';
       /*$sql = 'SELECT * FROM users WHERE email="'.$email.'" ';*/
        // use prepared statements, even if not strictly required is good practice
        $stmt = $dbh->prepare( $sql );

        // execute the query
        $stmt->execute();

        // fetch the results into an array
        $result = $stmt->fetchAll( PDO::FETCH_ASSOC );


        // convert to json
        $json = json_encode( $result );

 echo "------"; print_r($result); echo "-------";
        // echo the json string
/*        echo $json;
        */# code...



?>

和我的登录功能它使用Controller&#39; Users&#39;

$scope.login = function(){
    console.log("loginFunc");
     $http.post('http://localhost/2404/news_to_angular/php/login.php')
     .then(function(response) {
            // here the data from the api is assigned to a variable named users
            console.log(response.data);
            $scope.users = response.data;
             isLoggedin = true;


  })


}

并在控制台中显示 ------阵列 (     [0] =&gt;排列         (             [email] =&gt;             [密码] =&gt;         )

[1] => Array
    (
        [email] => 
        [password] => 
    )

[2] => Array
    (
        [email] => 
        [password] => 
    )

[3] => Array
    (
        [email] => 
        [password] => 
    )

[4] => Array
    (
        [email] => 
        [password] => 
    )

[5] => Array
    (
        [email] => 
        [password] => 
    )

[6] => Array
    (
        [email] => 
        [password] => 
    )

[7] => Array
    (
        [email] => 
        [password] => 
    )

[8] => Array
    (
        [email] => 
        [password] => 
    )

[9] => Array
    (
        [email] => 
        [password] => 
    )

[10] => Array
    (
        [email] => 
        [password] => 
    )

[11] => Array
    (
        [email] => 
        [password] => 
    )

[12] => Array
    (
        [email] => 
        [password] => 
    )

[13] => Array
    (
        [email] => 
        [password] => 
    )

0 个答案:

没有答案