dunno why you didn't get an error for the space after "databasename "
but anyway...you say you've only got one database
you've already selected it using mysql_select_db
so you don't need to clarify it again in the SQL
"INSERT INTO `databasename `.`$tableentry` (`id` ,`ti.....
just try
"INSERT INTO `$tableentry` (`id` ,`ti
and if that doesn't work...then I dunno.
If there's only one table why do you need a variable to hold the tableentry anyway....just put it explicity
"INSERT INTO `yourtablenamehere` (`id` ,`ti