At 18:37 -0700 10/5/03, jmulkerin wrote:
I used the  placeholders and it works.
Thanks.
I still don't undertand why it didn't work the fisrt time.

For exactly the reason I indicated. The query you were executing was:



INSERT INTO log (Nbr, Bdate, dtime) VALUES (123456, 10012003, 0928A)

For the query to be correct, it would have to be:

INSERT INTO log (Nbr, Bdate, dtime)
VALUES (123456, '10012003', '0928A')

You didn't quote the data values that needed to be quoted.
Remember, MySQL allows column names to begin with a digit,
so an unquoted 0928A is taken to be a column name.



John ----- Original Message ----- From: "Paul DuBois" <[EMAIL PROTECTED]> To: "jmulkerin" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, October 05, 2003 5:42 PM Subject: Re: Beginner's insert problem results in unknown column value


 At 16:01 -0700 10/5/03, jmulkerin wrote:
 >Oh most literate ones, can you tell me what's wrong?

 You didn't quote your data values, so they appear to be
 column references.

Use placeholders instead, you'll be happier:

 my $stmt = qq {INSERT INTO log (Nbr, Bdate, dtime)
           VALUES (?,?,?)};
 my $sth = $dbh->prepare( $stmt) || die "prepare: $stmt: $DBI::errstr";
 $sth->execute($Nbr, $Bdate, $Dtime) || die "execute: $stmt: $DBI::errstr";


> >I get this error: >DBD::mysql::st execute failed: Unknown column '0928A' in 'field >list' at test3.pl line 20.
> >execute: INSERT INTO log (Nbr, Bdate, dtime)
> VALUES (123456, 10012003, 0928A): Unknown column '0928A in
> >'field list' at test3.pl line 20.
 >
 >>From this script:
 >#use strict;
 >#use DBI qw(:sql_types);
 >use DBI;
 >#my $dbh;
 >my ($username, $password, $eamil, $Bdate, $AcctNbr, $Dtime);
 >my $username = 'jblowk';
 >my $password = 'abcdefg';
 >my $email = '[EMAIL PROTECTED]';
 >my $Bdate = '10012003';
 >my $Nbr = '123456';
 >my $Dtime = '0928A';
 >DBI->trace(2,"dbi.out"); # trace everything to
 >                               # dbi.out
 >my ($username, $password, $email);
 >#my ($dbh, $sth, $count);
 >$dbh = DBI->connect ("DBI:mysql:database=logbase;host=localhost;
 >'userid', 'password'") or die ("Can't connect to logbase");
 >my $stmt = qq {INSERT INTO log (Nbr, Bdate, dtime)
 >          VALUES ($Nbr, $Bdate, $Dtime)};
 >my $sth = $dbh->prepare( $stmt) || die "prepare: $stmt: $DBI::errstr";
 >$sth->execute || die "execute: $stmt: $DBI::errstr";
 >$sth->finish ();
 >$dbh->disconnect ();




Reply via email to