
earachefl
Novice
Aug 9, 2009, 1:54 PM
Post #1 of 6
(4936 views)
|
|
Insert syntax question
|
Can't Post
|
|
I'm trying to complete a tutorial on inserting files to a database. In a previous tutorial, I had been able to successfully connect to this database and print the contents. Now I get an error message:
DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3. (SQL-07002) at C:\perlscripts\lab11-2.pl line 61, <STDIN> line 5. Line 61 is:
$sql = qq{INSERT INTO cartable (year, make, model, color, price) VALUES($year, $make, $model, $color, $price);}; The textbook includes a completed lab in which that line reads:
$sql = qq{INSERT INTO cartable (year, make, model, color, price) VALUES ($year, '$make', '$model', '$color', '$price');}; which compiles and runs fine. As far as I can see, the only difference is the addition of single quotes to the last 4 values. I am puzzled as to why this would work. For what it's worth, my original code for the offending line was:
$sql = "INSERT INTO cartable ('year', 'make', 'model', 'color', 'price') VALUES($year, $make, $model, $color, $price)"; which gives the same error message as above but with "Expected 4" instead of "Expected 3".
|