in reply to dbi insert
It looks a bit intimidating, but you only need to worry about changing ONE line (the first one in this example) if you add or subtract fields. Read up on map and join for more info. :)my @fields = qw(fornavn efternavn cpr adresse zip city tjenestested); my $cgi = new CGI; # apply validation/error checking as needed # in this case, if no param is found, undef is default my @params = map { $cgi->param($_) || undef } @fields; # connect to database . . . my $sth = $dbh->prepare( 'INSERT into people(' . join(',', @fields), ') values(' . join(',', map { '?' } @fields), ')' ) or die $dbh->errstr; $sth->execute(@params) or die $dbh->errstr;
jeffa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: dbi insert
by Anonymous Monk on Oct 17, 2001 at 12:37 UTC | |
by tommyw (Hermit) on Oct 17, 2001 at 12:45 UTC | |
by Anonymous Monk on Oct 17, 2001 at 15:48 UTC | |
by tommyw (Hermit) on Oct 17, 2001 at 16:03 UTC | |
by jeffa (Bishop) on Oct 17, 2001 at 19:51 UTC |