First, let me help you. You're working much too hard. That first bit of code should go like this:

my $tstr = join(',', ('?') x @table); my $tv = join(',', @table);

Now your error comes when you try to call execute using @data:

$sth->execute( @data) || die("Error: Can't execute: $DBI::errstr +");

I'm pretty sure this is happening because @data has one less item than @tables. Try putting this before the execute:

die "Hey, \@data should have " . scalar(@table) . " values but it only has " . scalar(@data) . "!" if @data != @table;

The error message generated should explain the problem to you. If not, post more code and maybe the real problem will be more clear.

-sam


In reply to Re: DBI SQL adding array of values by samtregar
in thread DBI SQL adding array of values by pmtolk

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.