Just check it out whether $tablename is set or not?.
i crate a table like this...
#!/usr/bin/perl
use CGI;
use DBI;
$dbh=DBI->connect('dbi:mysql:databasename','username','pwd');
#connect to the database ..
#enter your database name ,username and password to the connection string..
$sql="create table tblname(name varchar(30))";
#create table command.
$sth = $dbh->prepare($sql)
or die "Can't prepare $sql: $dbh->errstrn";
#pass sql query to database handle..
$sth->execute
or die "can't execute the query: $sth->errstrn";
#execute the query here.
###############---
After this try to insert some record into it.
or
probably you can issue a "show tables" command to see wether your table is existing in the database or not.
------------------
SR -
shiju.dreamcenter.net
"The fear of the LORD is the beginning of knowledge..."