Fellow monasterians, I have successfully used placeholders in previous projects, but running into a problem with this one. Getting the Can't call method 'prepare' on an undefined value at... error. In checking with the DBI docs on CPAN I see nothing unusual.

My guess is that the fields in my database are not matching up with the placeholders. My fields are named exactly as the scalars you see in the code, and the empty values you see at the beginning and end of the list in the 'execute' statement are for the auto-incremented id and a TIMESTAMP.

However, no matter how I adjust the number of ? marks or execute values, I get the error (in the code below their are 17 ?'s and 17 values). A recent node by grinder that mentions the placeholder for an auto incre. id is not necessary (however, I have found in other scripts this was necessary--weird). What about the TIMESTAMP? Does it need a placeholder? Anyway, here's the suspect code. Thanks!
$sth = $dbh->prepare (q{ INSERT INTO sponsor VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)} ); $sth->execute ('', $name, $address, $city, $state, $zip, $country, $contact, $title, $phone, $bestime, $email, $license, $type, $capacity, $distributor, '' );
Update:
Something injunjoel said caused me to go back and discover my problem was coming before the prepare and execute statements. I learned a valuable lesson. But I also learned a lot about placeholders, and I'm indebted again to the monastery for wise replies. Problem solved and code improved. Thanks. Also, fixed references from injunjoe to injunjoel (I need new glasses).

—Brad
"A little yeast leavens the whole dough."

In reply to Using placeholders in MySQL returning an error by bradcathey

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.