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

Hi Monks, I'm new to Perl and CGI. I'm trying to pass data from one form to another form. My problem is that as I pass data between the forms, the new data overrides the previous entries. For example, if someone enters a choice of blue and submits then enters green. They have two entries of green instead one of blue and one of green. Any ideas as to why this is happening? Thanks.

Replies are listed 'Best First'.
Re: Passing Data
by vek (Prior) on Jan 23, 2003 at 22:23 UTC
    Welcome to the Monastery b310. You'll really need to post some code before we can begin to help you out with this.

    -- vek --
      Hi.... The first bit of code is the form that the user enters the information.
      sub get_product_table { my $sth = shift; my @row; while (my $ref = $sth->fetchrow_hashref ()) { # generate a form allowing a quantity of the item to be added # to the cart push (@row, start_form(-method=>'GET', -action=>url()), hidden( -name => "choice", -override => 1, -default => "add" ), hidden( -name => "item_id", -override => 1, -default => escapeHTML( $ref->{item_id} )), Tr ( td ( escapeHTML( $ref->{item_id} )), td ( escapeHTML( $ref->{description} )), td ( { -align => "right" }, escapeHTML( sprintf( "%.2f", $ref->{pri +ce}))), td ( "" ), td ( textfield( -name => "quantity", -size => "2")), td (image_button( -name => "Add Item", -src=>"../images/add.jpg", - +border=>"0" ))), end_form() ); } $sth->finish (); return undef unless @row; # no items? unshift (@row, Tr ( # put header row at beginning th ("Item"), th ("Description"), th ("P +rice"), th ("" +), th ("Q +ty"), )); return (table ({-border => 0, -align => "center"}, @row)); }
      The next bit of code is the next form that reads the inputted data and allows the user to make changes.
      push (@row, start_form(-method=>'GET', -action=>url()), hidden( -name => "choice", -override => 1, -default => "update" ), hidden( -name => "item_id", -override => 1, -default => escapeHTML( $i +tem_id )), Tr ( td ( escapeHTML( $item_id )), td ( textfield( -name => "quantity", -s +ize => "2")), td (escapeHTML ($item_ref->{description})), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $item_ref->{price +}))), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $total_item_price +))), + ($show_links ? td (a ({-href => $url}, img ({-src => "../im +ages/delete.jpg", -border => "0"}))) + : td (" ")), end_form()
      If you need more info, let me know. Thanks.
        It's hard to sort this out without seeing all the code but at a guess I would first look at where you have this in the first script
        hidden( -name => "item_id", -override => 1, -default => escapeHTML( $ref->{item_id} )),
        and this is the secomd
        hidden( -name => "item_id", -override => 1, -default => escapeHTML( $item_id )),
        and in particular, check the scope of $item_id
        poj