Most likely, there's something wrong in the SQL, which is causing the query to fail, and return false. Remember things like column names are case sensitive.
Also, your script is at heart a security catastrophe waiting to happen. What's to stop someone just POSTing 'DELETE FROM users' or something equally destructive?
If you're accepting input from elsewhere, you should use pre-prepared queries, or at the very least escape data before it goes anywhere near the database. Think what you're wanting to do, and consider an approach more like an API, eg include in the POST command a parameter that says what you want, and other options to specify parameters. For instance:
<?php
// set up the database as $mydb; using mysqli here, and object methods
$mydb = new mysqli('localhost','userName','password','database') ;
$mydb->query('set names utf8mb4') ;
$action = strtolower($_POST['ACTION']) ;
switch ( $action ) {
case 'getall' :
$query = "SELECT * FROM clients" ;
break ;
case 'getbyname' :
$query = sprintf("SELECT * FROM clients WHERE name = '%s'",$mydb->real_escape_string($_POST['NAME']) ;
break ;
}
$result = $mydb->query($query) ;
// check for an error, if you wish, here, then get the results:
$data = array() ;
while ( $r = $result->fetch_assoc() ) {
$data[] = $r ;
}
header('Content-Type: application/json; charset=utf-8') ;
print json_encode($data) ;
?>
I'd also seriously consider implementing some sort of security, even as simple as requiring an api key, without which no results will be returned.