in reply to Looping an array and placing into SQL

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'

Where do you want *them* to go today?

Replies are listed 'Best First'.
Re^2: Looping an array and placing into SQL
by Quicksilver (Scribe) on May 23, 2007 at 14:49 UTC
    Many thanks to both of you for your comments and help.