On Mon, 9 Sep 2002 at 22:08, Maureen E Fischer opined:

MEF:    I'm working on a Perl CGI program that must update
MEF:A mysql database.  The user enters key information that
MEF:Is used to display zero to many records.  Then the user
MEF:Can update or delete any number of records displayed.
MEF:I sucessfully displayed multiple records and have output
MEF:Them such that they can be modified.  I'm not sure 
MEF:Though when I submit the screen how I go through the
MEF:Multiple records.  I can't seem to find any examples in
MEF:The books that I have.  I output the multiple records using
MEF:A while and fetchrow_array.  I don't have any code to show
MEF:Because I am at a loss as to how to start.  Perhaps I can 
MEF:Just get the entire screen into one big field that I can

if you set up your form so that each record has the same <input> params, 
then they should be submitted in order and you can treat each one as an 
array.  for example (untested, and using limited html):

Name: <input type="text" name="name">
Address: <input type="text" name="address">
Phone: <input type="text" name="phone">
<input type="hidden" name="id" value="1">
<br>
Name: <input type="text" name="name">
Address: <input type="text" name="address">
Phone: <input type="text" name="phone">
<input type="hidden" name="id" value="2">


# and in your cgi:

my $dbh = put your db handle code here;
my $q = new CGI;
my @ids = $q->param('id');
my @names = $q->param('name');
my @addresses = $q->param('address');
my @phone = $q->param('phone');
my $sth = $dbh->prepare('update table set name=?, address=?, phone=?
                         where id=?');

for (my $i = 0; $i < scalar(@ids); $i++) {
  $sth->execute($names[$i], $addresses[$i], $phone[$i], $ids[$i]);
}

$sth->finish();
$dbh->disconnect;


of course, you'll need to do some validation to make sure values were 
submitted and are acceptable.  otherwise, scalar(@ids) may not be the 
same as scalar(@addresses) or scalar(@phone) or scalar(@names).  you'll 
probably want to check to make sure each value exists before trying to 
update it.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to