SQL Too few parameters. Expected 12 (1 Viewer)

PHP_Adam

New member
Local time
Today, 09:57
Joined
Feb 5, 2009
Messages
6
SQL Code
Code:
INSERT INTO 6dclient (contactid, Company, "First Name", "Last Name", "Business Phone", "Mobile Phone", "Fax Number", "Email Address", Address, City, "Postal Code", Notes) VALUES ("1", "cname", "fname", "lname", "onumber", "mnumber", "faxnumer", "emailnumber", "addnumber", "citynumber", "postocde", "notes");
The Error:
PHP:
Warning:  odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 12., SQL state 07001 in SQLExecDirect in D:\wamp\www\6degrees\pages\customerclientadd.php on line 25
As you can see, I ran the code from PHP. I doubt this will make any difference though. Why is the SQL saying too few parameters when I give it 12 columns and 12 peace's of data?

Im Lost on this one, tried everything I can think of. :confused:
 

SQL_Hell

SQL Server DBA
Local time
Today, 09:57
Joined
Dec 4, 2003
Messages
1,360
Code:
INSERT INTO 6dclient (contactid, Company, "First Name", "Last Name", "Business Phone", "Mobile Phone", "Fax Number", "Email Address", Address, City, "Postal Code", Notes) 
 
VALUES ("1", "cname", "fname", "lname", "onumber", "mnumber", "faxnumer", "emailnumber", "addnumber", "citynumber", "postocde", "notes");

Some of your columns have double quotes

"First Name", "Last Name", "Business Phone", "Mobile Phone", "Fax Number", "Email Address",
 

PHP_Adam

New member
Local time
Today, 09:57
Joined
Feb 5, 2009
Messages
6
Thank You SQL Hell. Unless Im missing something I get an error unless I do:
Code:
INSERT INTO 6dclientcontacts (contactid, Company, First Name, Last Name, Business Phone, Mobile Phone, Fax Number, Email Address, Address, City, Postal Code, Notes) VALUES ("1", "cname", "fname", "lname", "onumber", "mnumber", "faxnumer", "emailnumber", "addnumber", "citynumber", "postocde", "notes");
Error:
<b>
PHP:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in D:\wamp\www\6d\pages\customerclientadd.php on line 26
 

SQL_Hell

SQL Server DBA
Local time
Today, 09:57
Joined
Dec 4, 2003
Messages
1,360
The values should be in single quotes, not double quotes
 

PHP_Adam

New member
Local time
Today, 09:57
Joined
Feb 5, 2009
Messages
6
Code:
INSERT INTO 6dclientcontacts (`contactid`, `Company`, `First Name`, `Last Name`, `Business Phone`, `Mobile Phone`, `Fax Number`, `Email Address`, `Address`, `City`, `Postal Code`, `Notes`) VALUES ("1", "cname", "fname", "lname", "onumber", "mnumber", "faxnumer", "emailnumber", "addnumber", "citynumber", "postocde", "notes");

PHP:
[B]Warning[/B]:  odbc_exec() [[URL="http://localhost/6degrees/function.odbc-exec"]function.odbc-exec[/URL]]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 12., SQL state 07001 in SQLExecDirect in [B]D:\wamp\www\6degrees\pages\customerclientadd.php[/B] on line [B]26[/B]

I have tried now with single quote ` but I get same error.
 

SQL_Hell

SQL Server DBA
Local time
Today, 09:57
Joined
Dec 4, 2003
Messages
1,360
No

Your values should be in single quotes not your columns

like this:


Code:
INSERT INTO 6dclientcontacts (contactid, Company, First Name, Last Name, Business Phone, Mobile Phone, Fax Number, Email Address, Address, City, Postal Code, Notes) VALUES ('1', 'cname', 'fname', 'lname', 'onumber', 'mnumber', 'faxnumer', 'emailnumber', 'addnumber', 'citynumber', 'postocde', 'notes');
 

PHP_Adam

New member
Local time
Today, 09:57
Joined
Feb 5, 2009
Messages
6
Thank You SQL_Hell,
I have learned my lesson now, it worked running query like:
Code:
INSERT INTO 6dclientcontacts (contactid, `Company`, `First Name`, `Last Name`, `Business Phone`, `Mobile Phone`, `Fax Number`, `E-mail Address`, Address, City, `Postal Code`, Notes) VALUES ('1', 'cname', 'fname', 'lname', 'onumber', 'mnumber', 'faxnumer', 'emailnumber', 'addnumber', 'citynumber', 'postocde', 'notes');

Thank you very much,
but Now I have no excuse for watching tv.
 

wjs2031

New member
Local time
Today, 02:57
Joined
Jul 3, 2009
Messages
1
What may have thrown you here is something that has thrown me often. ACCESS (well ACCESS 2003 anyway) is more permissive with double quotes when you create queries within the database than when you submit them across an ODBC connection. For example, a query ending with something like .... and item6="home" .... will be interpreted properly when created and executed within the DB, but will not pass muster when submitted across an ODBC connection.

Part of the problem, I am guessing, may lie in the fact that Microsoft ACCESS (almost from its beginning) does not utilize single and double quote string delimiters as defined by public SQL guidelines, but rather defines bracket, double quote and quote delimiters under its own syntax. Thus more care is taken when queries are submitted from the outside.

If this is not correct, I'd be glad to apologize for this explanation, and would appreciate another explanation as to why its works within a (2003) ACCESS database but not across an ODBC connection.

Many thanks!
 

Madmart1gan

Registered User.
Local time
Today, 03:57
Joined
Mar 19, 2014
Messages
12
wjs2031, you brilliant person. I've been fighting this issue for two days trying to pass some reasonably simple query results to Excel via MS Query but have been getting this too few parameters error over and over. Turns out the " vs ' was the issue. I went and replaced all "s with 's and now I'm golden! Thank you for this!
 

Users who are viewing this thread

Top Bottom