Re: Multiple inserts to mysql using perl
Darren Duncan <[email protected]>
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <p05200f02bdb97fc89f6c@[24.108.166.215]> |
At 1:18 PM -0600 11/9/04, Lewick, Taylor wrote:
>Hi all, I have a simple web form where a user selects an application
>from a drop down menu and then enters email or phone number if they want
>alerts on that app...
>Simple, it goes right into database..
>But it has come to my attention that some users want to enter multiple
>emails and numbers at once on a form. That way they don't select an
>app, enter a name, hit submit and then start over, etc
Try something like this; every form field is a textbox with a unique
name; the Perl code is illustrative, not complete:
my $INSTANCES = 15;
sub print_form_fields {
foreach my $i (1..$INSTANCES) {
print <<__endquote;
<p>Email #$i: <input type="text" name="email_$i" value="" /><br />
Phone #$i: <input type="text" name="phone_$i" value="" /></p>
__endquote
}
}
sub store_form_values {
my ($email, $phone);
my $sth = $dbh->prepare( 'INSERT ...' );
$sth->bind_columns( \$email, \$phone );
foreach my $i (1..$INSTANCES) {
$email = CGI::param( 'email_'.$i );
$phone = CGI::param( 'phone_'.$i );
$sth->execute();
}
}
Let us know if something like that works for you.
-- Darren Duncan
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/[email protected]