Multiple inserts to mysql using perl

Multiple inserts to mysql using perl

am 09.11.2004 20:18:28 von tlewick

------_=_NextPart_001_01C4C690.E4768BD8
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi all, I have a simple web form where a user selects an application
from a drop down menu and then enters email or phone number if they want
alerts on that app...

Simple, it goes right into database..

=20

But it has come to my attention that some users want to enter multiple
emails and numbers at once on a form. That way they don't select an
app, enter a name, hit submit and then start over, etc

=20

Ok, so I created a form with up to 15 entries, looks nice, just not sure
how to go about gathering multiple fields and feed them into the
database. My main problem is in the variable naming..

=20

Here is an example using just the application name

=20

use DBI;

use CGI qw(:standard);

#not showing code for db connection and html headers, assume standard
stuff...

=20

print "

\n";

#this code loops through and creates 15 selection boxes for a user to
choose the application name...

for (1..15) {

print "
\n";

$query_apps=3D("select app_id, app_name from applications");

$sth =3D $dbh->prepare($query_apps);

$sth->execute();

$sth->bind_columns(\$appid, \$appname);

print "\n";

$sth->finish()

} #end of for loop

print "
\n";

=20

I used $_ so each time through it would see the value of the select box
name is appname1, then appname2, etc...

Then the hard part for me is getting multiple variables. I was thinking
I could either keep pushing onto an array the appname

But I cant say push (@array, appname$_) because that isn't a meaningful
variable...

or I could pass to another form or just call a subroutine I was hoping I
could do something like...

=20

sub Get_Items {

for (1..15) {

my ($A) =3D CGI::param("appname$_"));

print "App Name is $A
\n";=20

}

}

=20

but when I try this it never picks up a value for appname$_

Any ideas. Either I need to use the CGI module a better way, or I need
a little help on passing the variable or naming the variable.

=20

Thanks,

Taylor


------_=_NextPart_001_01C4C690.E4768BD8--

Re: Multiple inserts to mysql using perl

am 09.11.2004 21:15:21 von w

Taylor, --

> Any ideas. Either I need to use the CGI module a better way, or I need
> a little help on passing the variable or naming the variable.

Yes, cgi interface can return to you array of values
for single variable name,
so it's always better do not invent naming convention,
but rather use different type of internal data (array instead scalar).

Html SELECT also has multiple attribute,
and going there you would need array anyway.
In purpose of phone/email entry you seems to need instead.

--w


On Tue, Nov 09, 2004 at 01:18:28PM -0600, Lewick, Taylor wrote:
> Hi all, I have a simple web form where a user selects an application

> But it has come to my attention that some users want to enter multiple
> emails and numbers at once on a form. That way they don't select an
> app, enter a name, hit submit and then start over, etc
> for (1..15) {
> print "

Phone #$i:


__endquote
}
}

sub store_form_values {
my ($email, $phone);
my $sth = $dbh->prepare( 'INSERT ...' );
$sth->bind_columns( \$email, \$phone );
foreach my $i (1..$INSTANCES) {
$email = CGI::param( 'email_'.$i );
$phone = CGI::param( 'phone_'.$i );
$sth->execute();
}
}

Let us know if something like that works for you.

-- Darren Duncan

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org