使用动态表名在PHP中执行mySQL查询

I have a an android app which sends the table name as a parameter to a php script for executing a mySQL query. Problem is the table-name is a parameter (hence dynamic). I tried using the {$table_name} and backticks as suggested in some of the questions I read here, but nothing seems to work. Can someone tell the solution to this problem?

    <?php
    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "mmm";
    $connect = mysql_connect($dbhost, $dbuser, $dbpass);
    $tabn= $_POST['tabn'];
    $dt=$_POST['dt'];
    $query="INSERT into $tabn VALUES('$dt')";
    $result = mysql_query($query);
    if($result)
    {
    $response["success"]=1;
    }
    else
    {
    $response["error"]=1;
    }
    echo json_encode($response);
    ?>

The php script is as given above. I am getting error = 1 as the output in the android LogCat window.

Place

if(mysql_errno()){
   die(mysql_error());
}

Just after

$result = mysql_query($query);

It will show you MySQL error.

OR:

if(mysql_errno()){
    $response["error"]   = 1;
    $response["message"] = mysql_error();
} else {
    $response["success"] = 1;
}

Instead of:

if($result){
    $response["success"] = 1;
} else {
    $response["error"] = 1;
}
$tablename = $_POST['gettable'];
$data='this is data you want to insert';
mysql_query("insert into `$tablename`(`data`) values('$data')");

$tablename

It get the name of the table where data will insert.

$data

this is your data you want to insert.

When you want to insert data in your database and you want to select different table in one query. Then using this query you can insert data on different table.