On Wed, 2006-12-20 at 14:47 +0100, Huub wrote:

> $opdracht = "insert into woningen (complex,plaats,straat,huisnr) values 
> ($complex,$plaats,$straat,$teller)";
> $sth = $dbh->prepare($opdracht);
> $sth->execute or die "Connection Error: $DBI::errstr\n";
> ...
> It says 'Unknown column'. That is right: It's no column, it's data to be 
> inserted into the column. When I use the query directly in MySQL, 
> there's no problem. So what is going wrong here?

Non-numeric values need to be quoted properly for the database to
understand what you are trying to do. DBI provides an excellent way to
do the quoting automatically by using placeholders. Your queries are
better written as:

$opdracht = "INSERT INTO wonigen (complex,plaats,straat,huisnr) VALUES
(?,?,?,?)";
$sth = $dbh->prepare($opdracht);
$sth->execute($complex,$plaats,$straat,$teller)
  or die "Connection Error: $DBI::errstr\n";

Not only will this free you from worrying about how to quote the
variables, but it allows you to re-use the same statement with different
variables by passing different arguments to execute again.

-- 
Greg Sabino Mullane [EMAIL PROTECTED]
End Point Corporation

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to