我一直收到此错误通知:试图在PHP中获取非对象的属性:php错误

时间:2018-09-21 07:12:42

标签: php ionic3

我时不时地遇到这个问题。我尝试了很多方法,但没有成功。我怎么知道我要去哪里错了?这是我的PHP脚本:

    <?php 
    if (isset($_SERVER['HTTP_ORIGIN'])) {
            header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");

            header('Access-Control-Allow-Credentials: true');
            header('Access-Control-Max-Age: 86400');    // cache for 1 day
        }

        if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

            if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
                header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

            if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
                header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

            exit(0);
        }


    $mysql_host = "localhost";

    $mysql_database = "locationtracker";

    $mysql_user = "root";

    $mysql_password = "";

    // Create connection

    $conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);





    if ($conn->connect_error) {

        //die("Connection failed: " . $conn->connect_error);

    } 



    $postdata = file_get_contents("php://input");

        if (isset($postdata)) {

            $request = json_decode($postdata);

             $user= $request->username;



                    }






        $sql = "SELECT u_id FROM user_info WHERE login_id = '$user'";

          $result = mysqli_query($conn,$sql);

          $row = mysqli_fetch_array($result,MYSQLI_ASSOC);

          $active = $row['active'];

          $count = mysqli_num_rows($result);




          if($count >0) {

         $response= "Your Login success";

          }else {

        $response= "Your Login Email or Password is invalid";         

          }

     echo json_encode( $response);

    ?>

注意:此脚本将用于离子登录身份验证部分。

1 个答案:

答案 0 :(得分:0)

由于$row['active']导致错误,您没有在select语句中选择活动列。您更改了SQL查询的一些代码,如果条件成立,它将起作用。请尝试这对您有帮助。

 $sql = "SELECT u_id FROM user_info WHERE login_id = '$user'";

  $result = mysqli_query($conn,$sql);

  if(mysqli_num_rows($result) >0) 
   {
      $response= "Your Login success";
   } 
   else 
   {
      $response= "Your Login Email or Password is invalid";         
   }