api.php update

Added error detection if server return a sql error.