如何管理将Jsonobject中的int值放入查询?

The app send a String/Jsonobject with POST method to a PHP file. And I want to use that value to set the Limit in the query

$sql = "select * from posts ORDER BY post_id DESC LIMIT $tag";

I can receive it but i can't use it into my query. I got errors like "java.lang.string cannot be converted to jsonarray" I tried to convert it into Integer :

$int = intval($tag);

but the query still doesn't see it as an Integer..

There is another way to get an Int from Activity.java to php so that i can put it in the query after ORDER BY post_id DESC LIMIT ?

Java

 RequestQueue queue = Volley.newRequestQueue(this);
    Map<String, String> params = new HashMap<>();
    params.put("tag", "2");
    JSONObject o = new JSONObject(params);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
            Request.Method.POST,

Php

<?php

    //open connection to mysql db
        $connection = mysqli_connect("xxxxx","xxxx","xxxx","xxxx")
 or die("Error " . mysqli_error($connection));

    $data = json_decode(file_get_contents('php://input'), true);

    if (empty($data['tag']) == false) {
       $tag = $data['tag'];
    }

            //fetch table rows from mysql db 
        $sql = "select * from posts ORDER BY post_id DESC LIMIT $tag";

        $result = mysqli_query($connection, $sql) 
or die("Error in Selecting " . mysqli_error($connection));

Can you please try this

$sql = "select * from posts ORDER BY post_id DESC LIMIT '".$tag."';";