I think that this is the most common format:
$query = "INSERT INTO tablename SET id = '4'";
So, you can easily come back and perform variable expansion like this:
$id = 4;
$table = "tablename";
$query = "INSERT INTO $table SET id = '$id'";
If the 4
is something passed in by the user, you would instead use parametrized queries and bind the parameter to avoid SQL injection:
$id = $_POST["id"];
$table = "tablename";
$stmt = $con->prepare("INSERT INTO $tablename SET id=:id");
$stmt->bindParam(":id", $id);
$stmt->execute();