MySQL Forums
Forum List  »  Perl

Re: fetch a problem to insert values in perl programming
Posted by: Felix Geerinckx
Date: May 18, 2005 06:01AM

arupratan biswas wrote:

> $sqlstatement="INSERT INTO new_user
> (emp_id,emp_name,emp_add,city,zip_code,dob,phone)
> VALUES('$emp_id','$emp_name','$emp_add','$city',$zip_code,'$dob','$phone')";
> $sth = $dbh->prepare($sqlstatement);
> $sth->execute ||
> die "Could not execute SQL statement ... maybe invalid?";

In my personal view, the above is bad coding practice. I always use placeholders:

my $sqlstatement = qq{
INSERT INTO new_user
(emp_id, emp_name, emp_add, city, zip_code, dob, phone)
VALUES(?, ?, ?, ?, ?, ?, ?)
my $sth = $dbh->prepare($sqlstatement) or die "Could not prepare statement: $DBI::errstr";
$sth->execute($emp_id, $emp_name, $emp_add, $city, $zip_code, $dob, $phone)
or die "Could not execute: $DBI::errstr;

In your case, add the value of your sql statement to the die message, to see if the insert contains what you think it contains:

... die "Could not execute '$sqlstatement' ...";

Please use BBCode to format your messages in this forum.

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.