You really should consider using placeholders, as in:
#!/perl/bin/perl -w use strict; use Data::Dumper; # Added for test purposes my $lname = "foo"; my %fd = ( txtName => "", txtCreated => "2007-04-04", txtDateren => "", txtOldname => "Jackson", txtDel => "", ); # The actual code... my %cols = ( txtName => "Listname", txtCreated => "DateCreated", txtDateren => "DateRenamed", txtOldname => "OldListname", txtDel => "DateDeleted", ); my @values = (); my @fields = (); for ( qw/ txtName txtCreated txtDateren txtOldname txtDel / ) { push (@fields, $cols{$_} . "=" . '?'); push (@values, ($fd{$_} eq '') ? 'NULL' : $fd{$_}); } my $updatestring = join(', ', @fields); my $SQL = qq( UPDATE table SET $updatestring WHERE tbl.field = '$lname' ); print $SQL; my $sth = $db->prepare($SQL); $sth->execute(@values); __OUTPUT__ UPDATE table SET Listname=?, DateCreated=?, DateRenamed=?, OldListname=?, DateDelet +ed=? WHERE tbl.field = 'foo'
In reply to Re: Looping an array and placing into SQL
by thezip
in thread Looping an array and placing into SQL
by Quicksilver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |