By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

Error on Insert on a Access Data Base

P: 8
Hello,

I am having a problem that I can't seem to work out. I am running Apache 2.2 on a Windows XP platform, using PHP5. I am attempting to insert a row into a MS Access data base with a PHP script. I have a good connection into the data base, because select's work well.

The error that I am getting is:
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 5., SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\test.php on line 98 Error in SQL Insert statment please check code

from the statment:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO problems (Issue_key, user, phone, issue, Issue_Date ) SELECT "Issue ID 1" AS Issue_Key, "steve" AS user, "7777" AS phone, "test information" AS issue, "10/30/2007" AS Issue_Date; 
Has anyone seen this error, and knows what the cause may be? I would appreciate any advice very much.

Thank You
Oct 30 '07 #1
Share this Question
Share on Google+
8 Replies


P: 6
I don't use access too often but the last half of your query (SELECT "Issue ID 1" AS Issue_Key, "steve" AS user, "7777" AS phone, "test information" AS issue, "10/30/2007" AS Issue_Date) looks incomplete. Select from what table?
Oct 30 '07 #2

P: 8
I don't use access too often but the last half of your query (SELECT "Issue ID 1" AS Issue_Key, "steve" AS user, "7777" AS phone, "test information" AS issue, "10/30/2007" AS Issue_Date) looks incomplete. Select from what table?
I don't work with access much either, this is a insert statment that I did with the GUI inside Access, then cut and pasted into the PHP code. When I cut the statment back into Access it works great with no error.
Oct 31 '07 #3

code green
Expert 100+
P: 1,726
Expand|Select|Wrap|Line Numbers
  1. SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 5., 
This is usually because you are using a wrong field name
Oct 31 '07 #4

P: 8
Expand|Select|Wrap|Line Numbers
  1. SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 5., 
This is usually because you are using a wrong field name
I checked and double checked the field names, then I can cut the insert statment and past it into a Access query inside Access and it works. This leads me to think that the field names are OK.

Thanks
Oct 31 '07 #5

code green
Expert 100+
P: 1,726
Required syntax varies between Access DB and Access query in PHP.
Try replacing the double quotes with square brackets where there is a field name space.
In fact why are the quotes there?

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO problems (Issue_key, user, phone, issue, Issue_Date ) SELECT [Issue ID 1] AS Issue_Key, "steve" AS user, "7777" AS phone, [test information] AS issue, "10/30/2007" AS Issue_Date;
Oct 31 '07 #6

P: 8
Required syntax varies between Access DB and Access query in PHP.
Try replacing the double quotes with square brackets where there is a field name space.
In fact why are the quotes there?

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO problems (Issue_key, user, phone, issue, Issue_Date ) SELECT [Issue ID 1] AS Issue_Key, "steve" AS user, "7777" AS phone, [test information] AS issue, "10/30/2007" AS Issue_Date;
I tried your suggestion:
Expand|Select|Wrap|Line Numbers
  1. $sql='INSERT INTO problems (Issue_key, user, phone, issue, Issue_Date ) SELECT [Issue ID 1] AS Issue_Key, ['.$Fname.'] AS user, ['.$Fphone.'] AS phone, ['.$Fissuetext.'] AS issue, ['.$Fdate.'] AS Issue_Date;';
  2.  
and still got the error:
Expand|Select|Wrap|Line Numbers
  1. Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 5., SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\test.php on line 97 Error in SQL Insert statment please check code
Thank you for your suggestion
Oct 31 '07 #7

code green
Expert 100+
P: 1,726
You have still got the semi colon within the query statement.
That is not required for any DB
Expand|Select|Wrap|Line Numbers
  1. AS Issue_Date;';
Change to
Expand|Select|Wrap|Line Numbers
  1. AS Issue_Date';
Nov 1 '07 #8

P: 6
I tried your suggestion:
Expand|Select|Wrap|Line Numbers
  1. $sql='INSERT INTO problems (Issue_key, user, phone, issue, Issue_Date ) SELECT [Issue ID 1] AS Issue_Key, ['.$Fname.'] AS user, ['.$Fphone.'] AS phone, ['.$Fissuetext.'] AS issue, ['.$Fdate.'] AS Issue_Date;';
  2.  
and still got the error:
Expand|Select|Wrap|Line Numbers
  1. Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 5., SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\test.php on line 97 Error in SQL Insert statment please check code
Thank you for your suggestion

So something is going on between the php source and the database. My first suggestion would be to output the query without posting to the database, copy it from the page and then paste it into the database. My guess is that maybe something like single quotes are not being escaped correctly or maybe some are missing. But you want to output the sql exactly as it is being passed to the database like

Expand|Select|Wrap|Line Numbers
  1. $sql='INSERT INTO problems (Issue_key, user, phone, issue, Issue_Date ) SELECT [Issue ID 1] AS Issue_Key, ['.$Fname.'] AS user, ['.$Fphone.'] AS phone, ['.$Fissuetext.'] AS issue, ['.$Fdate.'] AS Issue_Date;';
  2.  
  3. echo $sql;
  4.  
then copy the output and paste that into your database to see if that works. If that doesn't work then try to get it to work and that may narrow down your issue.
Nov 1 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.