in reply to Inserting values into a MySQL database

I believe this is a problem in your SQL syntax, not your Perl. In short, your SQL statement should be:

INSERT INTO Questions(Question,Answer_A, Answer_B, Answer_C, Answer_D, Answer_E, Correct_Answer) VALUES(?,?,?,?,?,?,?)

I claim no particular in-depth knowledge of MySQL, however, so I may be mistaken.

Update: http://www.sqlcourse.com may be useful in improving one's SQL-fu.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Re: Inserting values into a MySQL database
by dws (Chancellor) on Jan 14, 2002 at 06:15 UTC
    Chmrr is correct. In order for SQL to know what columns your are inserting into, you have to name them.  INSERT INTO Table VALUES (?,?) isn't sufficient. You need to specify the fields, via   INSERT INTO Table (a, b) VALUES (?,?) Think of it as a list of associations, but with an array of keys on the left, and an array of values (or placeholders) on the right.


    Update: According the the MySQL doc for INSERT, the column names are indeed optional. This is a bad practice, however, since it will break your code whenever you change a table. My recommendation is to always explicitly name columns.

Re: Re: Inserting values into a MySQL database
by gav^ (Curate) on Jan 14, 2002 at 06:39 UTC
    You don't actually have to specify the columns on an insert. If you don't you need to provide a value for each column in the order that they were created. However this shortcut syntax is error prone, any change to the database will probably break your code and it also stops you from using auto_increment/default columns.
    mysql> create table test (a int, b char(1)); Query OK, 0 rows affected (0.05 sec) mysql> insert into test values (1, 'A'); Query OK, 1 row affected (0.06 sec) mysql> insert into test (a, b) values (2, 'B'); Query OK, 1 row affected (0.06 sec) mysql> select * from test; +------+------+ | a | b | +------+------+ | 1 | A | | 2 | B | +------+------+ 2 rows in set (0.05 sec)