my $sql2 = qq/ INSERT INTO transaction_details (quantity, gross_sales) VALUES ($quantity, convert (money, $gross_sales)) /;
This will evaluate and replace $vars here before the loop (probably as undefs) Are you using strict? Can we have some more information is this a CGI using CGI.pm?

If so what I think you are trying to get at is something like :-

my $sql2 = qq/ INSERT INTO transaction_details (quantity, gross_sales) VALUES (?, convert (money, ?)) /;# using bind parameters my $sth = $dbh->prepare($sql); # Assuming that each row in the form has the form # {fieldname}_{rownnum} my %param = $cgi->Vars(); while my $key (grep /quantity_/ keys %param) { my $quantity = $cgi->param($key); $key =~ m/(\d+)$/; my $gross_sales = $cgi->param("gross_sales_$1"); my $rv = $sth->execute( $quantity, $gross_sales ); }
This is untested code and does not contain error handling but it should give a good idea of the kind things you should be looking at.

Hope it helps
UnderMine


In reply to Re: DBI SQL statement in while loop by UnderMine
in thread DBI SQL statement in while loop by peppiv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.