Gossamer Forum
Home : General : Perl Programming :

Is this possible, Enter multi. records on 1 submit

Quote Reply
Is this possible, Enter multi. records on 1 submit
Is this possible?

I am wanting to allow a user to enter multiple records at a time using only one submit button and then have it enter each record on a single line with it's own ID number in a flat file.

Every way I try it, it just enters all of the records on one line treating them as one record.

I have searched several boards and programs and cannot find an answer.

Thanks.

Jimmy Crow
http://www.homewithgod.com/
Quote Reply
Re: Is this possible, Enter multi. records on 1 submit In reply to
Could you explain a bit more please - it is hard to help with a brief amount of information.

Is this related to a GT script?

Installations:http://www.wiredon.net/gt/

Quote Reply
Re: Is this possible, Enter multi. records on 1 submit In reply to
Hello Paul,

I'll try and explain without getting too long. This is on a script I am writing. This is the last bit I can't figure out.

A visitor comes and want to add 6 entries. Rather than having the user add the entry on 6 different forms, I was wanting to have a multiple entry form where the user can add up to 10 entries at one time. My fields are ID, username, email, request, and request_type.

I have written the form entry once and then just copied the same form over 9 more times and encased it with one form tag at the beginning and one </form> and one submit button at the end.

I would like for the script to read each line as one entry, print it to the file and then go to the next line and do the same until it reaches a blank entry or all ten entries and then quit. Or possibly read all of the entries and then print them all at one time, one per line.

Since each entry within the forms have the same field names, it just fills in all of the remaining blanks entry lines and prints all of the information on one line as if it was one entry.

I was thinking I could accomplish this by using some sort of statement after the request_type field to begin a new line in the record file and an if (!$form{'username'}) statement to ignore the rest of the empty fields. The ID is a random number assigned to the entry.

Am I even on the right track? Thanks for the input.

Jimmy Crow
http://www.homewithgod.com/
Quote Reply
Re: Is this possible, Enter multi. records on 1 submit In reply to
Here's one way...
Code:
use CGI qw(:standard);
my (@name, @address) = (param('name'), param('address'));
open (DB, ">test.db") or die $!;
flock (DB, 2);
for (my $i; $i < 10; $i++) {
last unless ($name[$i] and $address[$i]);
print DB, join "|", (($i + 1), $name[$i], $address[$i]), "\n";
}
close DB;
Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: Is this possible, Enter multi. records on 1 submit In reply to
Thanks junko! I will give this a try.


Jimmy Crow
http://www.homewithgod.com/
Quote Reply
Re: Is this possible, Enter multi. records on 1 submit In reply to
Can't seem to get all of this to come together. I think I will give DBMan a try.

Jimmy Crow
http://www.homewithgod.com/
Quote Reply
Re: Is this possible, Enter multi. records on 1 submit In reply to
sorry, I should have tested that. Try this:

Code:
use CGI qw(:standard);
my @first = param('first');
my @last = param('last');
open (DB, ">test.db") or die $!;
for (my $i; $i < 10; $i++) {
last unless ($first[$i] and $last[$i]);
print DB (join "|", (($i + 1), $first[$i], $last[$i])), "\n";
}
close DB;
Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com