Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:

I'm making a simple database script that will update around 150+ rows with about 10 columns per row. So far I have it where the user can go and do an update on each row specifically, but they have to update one row at a time. Which can be annoying. Anyway, I need to figure out how to pass 150 x 10 = 1500 form variables (thats like worse case scenario) and have it do an update on the database (it also has a check to validate the data in between, but I'm not too concerned about that right now. My basic question is there a simple way to pass 1500 form variables from one page to another?
I understand the idea behind "don't reinvent the wheel" But currently I cannot use any modules as "I can't" install them.

Replies are listed 'Best First'.
Re: Passing a lot of form values
by blazar (Canon) on May 23, 2007 at 14:26 UTC
    My basic question is there a simple way to pass 1500 form variables from one page to another?

    Far from being an expert in these matters, but AIUI a POST does not have any limitation in this sense. What's the problem?

    I understand the idea behind "don't reinvent the wheel" But currently I cannot use any modules as "I can't" install them.

    Indeed you "can't", but you can, especially if they're pure Perl: otherwise yes, you may have some troubles.

Re: Passing a lot of form values
by starX (Chaplain) on May 23, 2007 at 14:28 UTC
    Lots of ways to store data and move it around in Perl. Lists, hashes, hashes of lists, etc all might be appropriate. Can you post some code that shows us how you're presently working with the data? I and others will be much better able to assist you if you do.
Re: Passing a lot of form values
by Trihedralguy (Pilgrim) on May 23, 2007 at 18:51 UTC
    Here is what I have so far, but it doesn't like it for some reason:
    #Get the row count my $sp = $dbh->prepare(" select ROWNUM FROM LAWL.HEHE_SECURITY ORDER BY ROWNUM DESC; "); $sp->execute(); my $myrowcounter = $sp->fetchrow_array; my $countrows = 1; my %incoming = &read_input; # Read information into associated # array %incoming. while ($countrows <= $myrowcounter) { my $qty[$countrows] = $incoming{'qty$countrows'}; # Fetch the text fro +m the array. my $type[$countrows] = $incoming{'type$countrows'}; # Fetch the text f +rom the array. my $equip[$countrows] = $incoming{'equip$countrows'}; # Fetch the text + from the array. my $dept[$countrows] = $incoming{'dept$countrows'}; # Fetch the text f +rom the array. my $fstore[$countrows] = $incoming{'fstore$countrows'}; # Fetch the te +xt from the array. my $dreceived[$countrows] = $incoming{'dreceived$countrows'}; # Fetch +the text from the array. my $rstore[$countrows] = $incoming{'rstor$countrowse'}; # Fetch the te +xt from the array. my $ringstore[$countrows] = $incoming{'ringstore$countrows'}; # Fetch +the text from the array. my $dated[$countrows] = $incoming{'dated$countrows'}; # Fetch the text + from the array. my $comment[$countrows] = $incoming{'comment$countrows'}; # Fetch the +text from the array. my $id[$countrows] = $incoming{'id_$countrows'}; # Fetch the text from + the array. my $action[$countrows] = $incoming{'action_$countrows'}; # Fetch the t +ext from the array. }

    syntax error at massupdate.cgi line 388, near "@qty[" syntax error at massupdate.cgi line 389, near "@type[" syntax error at massupdate.cgi line 390, near "@equip[" massupdate.cgi had compilation errors.
      my $qty[$countrows] = $incoming{'qty$countrows'};
      ?? did you really mean to do the my within the while? Also I don't see $countrows being incremented. How about declaring the arrays outside of the while loop?
      my (@qty, @type,@equip,@dept); #etc. while ($countrows <= $myrowcounter) { $qty[$countrows] = $incoming{'qty$countrows'}; $type[$countrows] = $incoming{'type$countrows'}; $equip[$countrows] = $incoming{'equip$countrows'}; $dept[$countrows] = $incoming{'dept$countrows'}; #etc. $countrows++; }
      Not sure if there was anything else wrong but that was my 1st thought. Hope that helps. -- Carmen
Re: Passing a lot of form values
by Trihedralguy (Pilgrim) on May 23, 2007 at 14:41 UTC
    It's very long, I have a lot of comments but you *should* be able to follow it:


    Please note I'm very much a perl noob and this script is very messy cause I'm still trying to build the function of it.
    So basically right now I'm doing that while to create about 150 "forms" and once they do an update it posts the variables in the URI which then takes it in and re-separates into its values then see's if the user is doing an update add delete, does the action and moves on. I just cant think of how I would make this work with 1 form and passing 1500 form fields.

    Readmore tags added by Arunbear

      Okay... first, especially if you're new at anything, comments are your friend. Spell out in detail what you expect to start with, what you expect to end with, and how you expect to get there. You'll help yourself figure it out, and others. Anyway, am I correct in thinking that this is the collection of data you're needing to move around?
      my %incoming = &read_input; # Read information into associated # array %incoming. my $qty = $incoming{'qty'}; # Fetch the text from the array. my $type = $incoming{'type'}; # Fetch the text from the array. my $equip = $incoming{'equip'}; # Fetch the text from the array. my $dept = $incoming{'dept'}; # Fetch the text from the array. my $fstore = $incoming{'fstore'}; # Fetch the text from the array. my $dreceived = $incoming{'dreceived'}; # Fetch the text from the arra +y. my $rstore = $incoming{'rstore'}; # Fetch the text from the array. my $ringstore = $incoming{'ringstore'}; # Fetch the text from the arra +y. my $dated = $incoming{'dated'}; # Fetch the text from the array. my $comment = $incoming{'comment'}; # Fetch the text from the array. my $id = $incoming{'id'}; # Fetch the text from the array. my $action = $incoming{'action'}; # Fetch the text from the array.
      If that's the case, you might consider storing the information as a hash...
      my %data; $data{'qty'} = $incoming{'qty'}; $data{'type'} = $incoming{'type'}; # etc...
      And then after you've populated your hash, add it to a list...
      my @hashes; push @hashes, $data;
      And then you can just access the members of the list sequentially when you need to update the database. Or am I missing something in your code?
        That seems like what I may need to do. I can develop my own "logic" to process this stuff". But I think you've answered my simple question about how I can go about sending and receiving (the possibility of 150 rows of data) my data using form variables.
        I have a quick quesiton, when you say "And then after you've populated your has, add it to a list". What do you mean by this?
        Also when the time comes how to I call a row of data. So if I have like 1 2 3, 1 2 3 (qty, number, stock) How do I call row one then row two of the $data?
      It's very long, I have a lot of comments but you *should* be able to follow it:

      Nope. You may consider at least putting that in <readmore> tags...

      I just cant think of how I would make this work with 1 form and passing 1500 form fields.

      What's wrong with the fields having names like "row1col1"... "row150col10"?

        I thought it was a bad practice to have 1500 variables?