in reply to Perl DBI, multiple values question

Please can you clarify exactly what you want to do?

Are you saying that you have a form with multiple values (ie. member, username, firstname, surname, password and you wish to enter) these then need to be split out into one row per key pair.

Or

Are you saying that your have five member only records each to be added as a seperate record

Or

A combination of the two above (ie. member, username, firstname, surname, password five times over)
This will require that there is some relationship between each of the fields in a row. ie name=member_1, name=username_1, name=member_2, name=username_2 in the form input fields.

Some additional information about the database schema would also be helpful.

Hope it helps
UnderMine

Replies are listed 'Best First'.
Re: Re: Perl DBI, multiple values question
by Jokerman_se (Initiate) on Nov 22, 2002 at 15:28 UTC
    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!

      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