Entry
What does a "too few parameters" error message mean?
What is a common cause of the "too few parameters" error message?
Jul 4th, 1999 04:57
Nathan Wallace, Brad Marsh
When inserting data into a database it expects a certain number of
parameters, one for each column in the table. If you use the insert
sytax to specify the columns then you need to provide data for each
column.
If you do not specify as many parameters as there are columns then you
will get a "too few parameters" error.
This may also occur when you do not format your SQL correctly. In
particular you need to be careful to include single quotes around
strings.
An example:
$fname = fname;
$lname = lname;
$connection = odbc_connect("phpdb","","");
$query = "INSERT INTO patient (fname, lname) ";
$query .="VALUES ($fname, $lname) ";
gives the following error:
Warning: SQL error: [Microsoft][ODBC Microsoft Access 97 Driver] Too
few parameters. Expected 2., SQL state 07001 in SQLExecDirect in
c:\apache136\htdocs/newpatient.php3 on line 8
But if you use single quotes around the names when creating your query
above like so:
$query = "INSERT INTO patient (fname, lname) ";
$query .="VALUES ('$fname', '$lname') ";
the error will not occur.