You don't _have_ to specify the columns as gav^ rightly points out. BUT! You don't have to use strict either. ;)

The problem is this line:

my($TN,$Question,$AnswerA,$AnswerB,$AnswerC,$AnswerD,$Correct)=...
What happened to Answer E? :)

What you end up with is trying to insert only 7 variables where DBI is expecting 8.

In the long run though, follow the advice of Chmrr, dws, and Ovid. It will keep you out of trouble.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

P.S. Brownie points to adamsj for spotting this error too.

P.P.S Or i could be completely wrong about Answer E. I now see that you are indeed assigning the variable $AnswerE to "NULL", which is not the same as NULL. Use undef instead, but you really should specify $AnswerE in the split, i think. How about this instead:

foreach my $element(@Array){ chomp $element; # define $STH as you did $STH->execute(split/\|/,$element,8); }
As long as you really include Answer E with the rest in the data file, this code allows you to avoid using temp variables - just pass the output of split. Of course, you might want to do some validation, passing the contents without validating them is not a good thing.

In reply to (jeffa) 2Re: Inserting values into a MySQL database by jeffa
in thread Inserting values into a MySQL database by TStanley

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.