List Info

Thread: Any Number Of CGI Params




Any Number Of CGI Params
country flaguser name
United States
2007-09-20 03:27:10

Here's my situation. I'm writing a CGI web form that works in 3
steps. Ask user how many rows to display for data entry, display the
rows of form fields for user to enter data, and then read the entered
data into the CGI script. My problem is looping through the entered
data. If I only had one row of user data to receive, my code would
look like this:

my %one_row = (
name => param ("name"),
age => param ("age"),
favorite_perl_author => param ("author"),
);
loop through hash and build SQL ......
connect to db........
insert .......
...........

So what I'd like to do would be to enclose this in a while loop like
this: while (each set of params is received) { ...... I just
don't know what condition to test for in the while loop.

Let me know if I'm heading in the right direction. If so, what steps
do I need to take and where can I find documentation on this? If not,
what am I doing wrong and what do you suggest?

Thank you,

+++++++;+++3;+++++++++++++3;++++
Joe Catanzaro
runordie%40gmail.com">runordiegmail.com

__._,_.___
.

__,_._,___
Re: Any Number Of CGI Params
country flaguser name
United States
2007-09-20 10:24:36

>>&gt;>> "Joe&quot; == Joe Catanzaro < runordie%40gmail.com">runordiegmail.com> writes:

Joe> my %one_row = (
Joe>; name => param ("name"),
Joe> age => param ("age"),
Joe> favorite_perl_author => param ("author"),
Joe> );

This is already dangerous. param(&quot;name";) in a list context (as you have
it) could return 0, 1, 2, 3, ... n values, corresponding to the number
of fields with the same name in the incoming parameter load. For example,
if the incoming data was:

<input type='hidden' name='name' value='aaa'>
<input type='hidden' name='name' value='bbb'>
<input type='hidden' name='name' value='ccc'>

You'd get aaa, bbb, ccc, and you'd end up with a hash key of bbb with
a value of ccc. Worse, if it returns an even number, all the even/odd
items building your remaining hash will break.

The solution is to use "scalar" in front of param, or use a map:

my %one_row = map { $_ => scalar param($_) } qw(name age author);

Joe> So what I'd like to do would be to enclose this in a while loop like
Joe> this: while (each set of params is received) { ...... I just
Joe> don't know what condition to test for in the while loop.

I don't understand what "each set of params received&quot; means. If you have
only one field named 'age', you'll get only one entry.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
Re: Any Number Of CGI Params
country flaguser name
United States
2007-09-27 03:54:42

Thanks for the response.

I'm trying to build on your Perl example so that I can read in
name/value pairs similar to your HTML example. That is, many values
to one name relationship. So far my attempts only read in the first
name/value pair.

Thanks,

Joe

At 9/20/2007 08:14 AM Thursday, Randal L. Schwartz wrote:

> >>&gt;>> "Joe&quot; == Joe Catanzaro
> <<mailto: runordie%40gmail.com">runordiegmail.com> runordie%40gmail.com">runordiegmail.com> writes:
>
>Joe> my %one_row = (
>Joe> name => param ("name"),
>Joe>; age => param ("age"),
>Joe> favorite_perl_author => param ("author"),
>Joe&gt; );
>
>This is already dangerous. param(&quot;name";) in a list context (as you have
>;it) could return 0, 1, 2, 3, ... n values, corresponding to the number
&gt;of fields with the same name in the incoming parameter load. For example,
>if the incoming data was:
>;
> <input type='hidden' name='name' value='aaa'>
>; <input type='hidden' name='name' value='bbb'>
>; <input type='hidden' name='name' value='ccc'>
>;
>You'd get aaa, bbb, ccc, and you'd end up with a hash key of bbb with
>;a value of ccc. Worse, if it returns an even number, all the even/odd
>items building your remaining hash will break.
&gt;
>The solution is to use "scalar" in front of param, or use a map:
>;
>my %one_row = map { $_ => scalar param($_) } qw(name age author);
>
>;Joe> So what I'd like to do would be to enclose this in a while loop like
>;Joe> this: while (each set of params is received) { ...... I just
>;Joe> don't know what condition to test for in the while loop.
&gt;
>I don't understand what "each set of params received&quot; means. If you have
>;only one field named 'age', you'll get only one entry.
&gt;
>--
>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
>;<<mailto: merlyn%40stonehenge.com">merlynstonehenge.com> merlyn%40stonehenge.com">merlynstonehenge.com>
><;URL:http://www.stonehenge.com/merlyn/>
&gt;Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
>;See <http://PerlTraining.Stonehenge.com>PerlTraining.Stonehenge.com
>for onsite and open-enrollment Perl training!

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Any Number Of CGI Params
country flaguser name
United States
2007-09-27 08:05:29

>>&gt;>> "Joe&quot; == Joe Catanzaro < runordie%40gmail.com">runordiegmail.com> writes:

Joe> I'm trying to build on your Perl example so that I can read in
Joe> name/value pairs similar to your HTML example. That is, many values
Joe> to one name relationship. So far my attempts only read in the first
Joe> name/value pair.

What do your form names look like for that? That'll define how you
retrieve them.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )