Question: I have a JSON source and want to get results from it with a post request.

When I test with POSTMAN extension in chorme it works really well. But when I do that with angularJS the page keep loading and chrome consoles shows errors.

My code is here:

```
angular.module('loginApp', []).controller('loginController', function ($scope, $http) {
$scope.userName = '';
$scope.userPass = '';
$scope.output = function () {
    var params = JSON.stringify({
            username: '******',
            password: '******'
        });
    $http({url: "http://xx.xx.xx.xx/api/user/login.json",
        method: 'POST',
        data: params,
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }
    }).then(function (response) {
        return response;
    });
};
});

```

Any help would be appreciated :)

Answer: 
You want to show the "No results found"-message when no rows are found in the database table.

To do this, you can use below PHP and SQL code:

```
$sql = "SELECT * FROM search WHERE isbn='$isbn' OR bookname='$bookname' OR author='$author' OR category='$category'";
$query = $db->prepare($sql);
$query->execute();
$rows = $query->fetch(PDO::FETCH_NUM);
if($rows[0]) { 
    // Row exists
} else {
    echo "No results found in the database. Please go back and search again.";
}

```

Note that the above answer is vulnerable to SQL injection attacks. 
To prevent SQL injection attacks, it is recommended that you prepare and bind all user-submitted data, here is a better example that shows how SQL injection attacks can be prevented: (full example, including database connection)

```
$db = new PDO($dsn);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = $db->prepare("SELECT * FROM search WHERE isbn=:isbn OR bookname=:bookname OR author=:author OR category=:category");
$query->execute([ ':isbn'=>$isbn, ':bookname'=>$bookname, ':author'=>$author, ':category'=>$category ]);
$rows = $query->fetch(PDO::FETCH_NUM);
if($rows[0]) { 
    // Row exists
} else {
    echo "No results found in the database. Please go back and search again.";
}

```
Assuming you are using [Mysqli](http://php.net/manual/en/mysqli.quickstart.php) ,

```
  //connect with mysql
    $conn = mysqli_connect("localhost", "user", "password", "db");
   //here is the query
    if($result = mysqli_query($conn,"SELECT * FROM search WHERE isbn='$isbn' OR bookname='$bookname' OR author='$author' OR category='$category'")){
       if(mysqli_num_rows($result) > 0){
          //mysqli_num_rows() returns the number of rows in a result . 
          //when it is greater than zero, it has some results 
       }
       else{
         echo "No results found in the database. Please go back and search again.";
         //Do something if no results returned
       }
    }
    //finally free the results
    mysqli_free_result($result);
mysqli_close($conn);

```