I would like to have one php file generating my site. Is there any way I can make the tablename a variable activated when the user presses a button and can I then pass the variable to the sql query?
Of course you can; you simply apply the same variable substitution rules as are used with all PHP strings.
$query = "insert into $table ...."