Building on what other monks have already stated, here is a pattern for you to use that might help with what you are trying to accomplish. I'm making a few assumptions here, but here goes:

my $queryObj = $db_handle->prepare( qq( insert into employee(id,first_name,last_name, address.line.2,address.line.3) values (?,?,?,?,?,?) ) ) or die "Could not prepare query: ".$db_handle->errstr;
Assuming you don't die due to syntax error, bad column names or other problems your next step somewhere in code would be
$queryObj->execute( ...insert value list here ... ) or die "Could not execute " . $queryObj->errstr;

As merlyn pointed out, beware of SQL injection attacks. Before I pass data from a CGI form I'm going to do some cursory validation at the very least if not stringent validation to make sure I'm getting back in my CGI input what I expected and not bad stuff.

Also, using placeholders and/or variable binding makes use of some of the strengths of using DBI in the first place. Otherwise it isn't worth the overhead.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: Error adding a record into a MySQL table: 'Unknown column ...' by blue_cowdawg
in thread Error adding a record into a MySQL table: 'Unknown column ...' by stanleyscup

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.