in reply to Re: Perl DBI, multiple values question
in thread Perl DBI, multiple values question

Sorry. I'll try to explain:

The form has 5 input fields for "subject" (forget "member"):
input type="text" name="subject" value="" ... repeated 5 times

The user can enter data in 1-5 five of these.

This gets passed on to the DBI script.
The script should produce one INSERT INTO statement for each value entered, such as:
"INSERT INTO subjects VALUES ($FORM{'subject'})";

(the table "subjects" consists simply of auto-incremented id and subject).

An easy way would of course be to name the input fields subject1, subject2 etc., but it would be better to solve it with some kind of loop.

Again, many thanks for your help!

  • Comment on Re: Re: Perl DBI, multiple values question

Replies are listed 'Best First'.
Re: Re: Re: Perl DBI, multiple values question
by UnderMine (Friar) on Nov 22, 2002 at 15:39 UTC
    The easiest way is to do this is probably :-
    my $dbh=DBI->connect(.....); my $query = "INSERT INTO subjects VALUES (?)"; my $sth=dbh->prepare($query); foreach my $subject (split /\0/,$form{'subject'}) { $rv = $sth->execute($subject); } $sth->finish(); $dbh->disconnect();
    Hope this helps
    UnderMine
      ...remembering to check the return values for the database calls...

      rdfield