in reply to Error while inserting null values with DBI

If $Id is undef or the empty string, your SQL becomes ...values(,"$name"), which is invalid SQL.

Use placeholders instead:

my $statement = $dbh->prepare('INSERT INTO test(id, name) VALUES(?,?)' +); $statement->execute($Id, $name);

This will work even if $Id is undef (if the db schema allows NULL values for id), or if $name contains quotes.