我尝试使用 dart 将数据发布到 php 后端。以某种方式使用 ajax,我可以获得响应,但是使用 dart,它显示 <b>Notice</b>: Trying to get property 'email' of non-object in <b>D:\xampp\htdocs\PHPBackend\api\login\login_account.php</b> on line <b>23</b><br />
<b>Notice</b>: Trying to get property 'password' of non-object in <b>D:\xampp\htdocs\PHPBackend\api\login\login_account.php</b> on line <b>24</b><br />
这些是我用于登录的 php 代码。
// login_account.php
$database = new Database();
$db = $database->getConnection();
$login = new Login($db);
$data = json_decode(file_get_contents("php://input"));
$login->email = $data->email;
$login->password = $data->password;
$login->loginAccount();
$login_arr = array(
"email" => $login->email,
"password" => $login->password
);
print_r(json_encode($login_arr));
?>
// login.php
function loginAccount(){
// query to read single record
$query = "SELECT
email, password
FROM
" . $this->table_name . " WHERE
email = :email AND password = :password";
// prepare query statement
$stmt = $this->conn->prepare( $query );
// sanitize
$this->email=htmlspecialchars(strip_tags($this->email));
$this->password=htmlspecialchars(strip_tags($this->password));
// bind id of food to be updated
$stmt->bindParam(":email", $this->email);
$stmt->bindParam(":password", $this->password);
die($this->email);
die($this->password);
// execute query
$stmt->execute();
// get retrieved row
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// set values to object properties
$this->email = $row['email'];
$this->password = $row['password'];
}
}
MM们
幕布斯6054654