473,625 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error on Insert on a Access Data Base

8 New Member
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
8 3666
w0rKInPHP
6 New Member
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
slb813
8 New Member
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
1,726 Recognized Expert Top Contributor
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
slb813
8 New Member
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
1,726 Recognized Expert Top Contributor
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
slb813
8 New Member
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
1,726 Recognized Expert Top Contributor
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
w0rKInPHP
6 New Member
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

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

Similar topics

1
8044
by: annie | last post by:
Hi all, I have recently ported my Access 2000 app to SQL Server, keeping the Access client as the front end using linked tables. I am also using triggers on my SQL tables to trap orphan records and validate added data. My question is..
4
2318
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes. Therefore the application errors out when deserializing the xml data. It places the some part of the child element
1
2917
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
7
6656
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
0
2257
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or updating the code-behind dll) accessing any aspx page in the application causes the application to run for the first time. Some of the initialization involves reading and writing some text and xml files using simple streamreader and streamwriter...
1
5398
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. And the line it shows in red is cmd.ExecuteNonQuery()
3
3720
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code in the application, but I'd rather not! DDL for table and trigger below. TIA
6
3447
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am using MS-Access 2000 database table for this app. Note that the datatype of all the fields mentioned above are Text. Apart from the above columns, there's another column in the DB table named 'RegDateTime' whose datatype is Date/Time which is...
2
2421
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into column 'EmployeeID', table 'Accomplishments.dbo.Accomplishment'; column does not allow nulls. INSERT fails. The statement has been terminated. and my code is this using System; using System.Collections;
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.