place error message in error class with php

  angular, php, typescript

I’m building APIs for a frontend application that requires login. I’m able to do the authentication alright. but I want to do it in a more enhanced way where if the username and password are wrong, I’d put it in an error class. C

$data= json_decode(file_get_contents("php://input"));
$userName= ($data->userName);
$userName= ($data->passWord);

$errorMsg=array("message"=>("wrong username or password"));

$row = $conn->query("SELECT * FROM members WHERE userName='".$userName."' and passWord='".$passWord."'");

$userDetails = $row->fetchAll();
$row_count = $row->rowCount();

if ($row_count > 0) {
    echo json_encode($userDetails);

} else {
    echo json_encode($errorMsg);



this.loginService.userLogin(this.userName, this.passWord).subscribe((data: any) => {

    if (data ) {
      console.log('it worked')

  }, err => {

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.