|
Trying to pass details from a form into an Access database. Although I get the following error:
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
I`ve checked the statement and I can`t really find any problems with the code. So could anyone please help me, I`m very very stuck...
asp page code -
<%
`Create object. In this case Connection to a database
Set Conn = Server.CreateObject("ADODB.Connection")
`Select provider
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
`Select data source.
`Server.MapPath function is equivalent to app.path function of VB
`It returns the directory in which the script is present
Conn.ConnectionString = "Data Source=" & Server.MapPath ("db/esurvedata.mdb")
`Open the connection
Conn.Open
Sub CheckValid(Str)
Str = Replace(Str, "`", "``")
If Str = "" THEN
Str = " "
End If
End Sub
strFname = server.HTMLencode(Request.Form("firstname"))
strSname = server.HTMLencode(Request.form("surname"))
strCname = server.HTMLencode(Request.form("companyname"))
strPosition = server.HTMLencode(Request.form("position"))
strEmail = server.HTMLencode(Request.form("email"))
strPhoneno = server.HTMLencode(Request.form("phoneno"))
Call CheckValid(strFname)
Call CheckValid(strSname)
Call CheckValid(strCname)
Call CheckValid(strPosition)
Call CheckValid(strEmail)
Call CheckValid(Phoneno)
strSQL="INSERT INTO esurvey(firstname, surname, companyname, position, email, phoneno) VALUES (` " & strFname & " ` , ` " & strSname & " ` , ` " & strCname & " ` , ` " & strPosition & " ` , ` " & strEmail & " ` , ` " & strPhoneno & " `)"
conn.execute strSQL
%>
osk
|
|
|
hi osk,
remark this function...
<%
`Call CheckValid(strFname)
`Call CheckValid(strSname)
`Call CheckValid(strCname)
`Call CheckValid(strPosition)
`Call CheckValid(strEmail)
`Call CheckValid(Phoneno)
%>
don`t need to check whether it contains value ` or ``.
hopefully it works.
"Gain More Knowledge" http://www.vss.com.my
|
|
|
|
|
it`s all good, found out that the coloumn name `position` could not be used in the database, not entirely sure why that is the case but after changing the coloumn name the code works fine!lol
osk
|
|
|
try replace
position
with
[position]
maybe it`s work.
|
|
|
|
|
Hi there, I keep getting the same error:
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
I`ve looked at my column headings and none of them seem to be one which is prohibited.
Here`s my code:
============================================================
` Open Database Connection
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.Mappath("storeDB.mdb")& "; Jet OLEDB:Database Password="
` Add New User to Database
sqlString = "INSERT INTO Users ( " &_
"user_username, " &_
"user_password, " &_
"user_email, " &_
"user_street, " &_
"user_town, " &_
"user_county, " &_
"user_postcode, " &_
"user_cctype, " &_
"user_ccnumber, " &_
"user_ccexpires, " &_
"user_ccname, " &_
") VALUES ( " &_
" `" & fixQuotes( newusername ) & "`, " &_
" `" & fixQuotes( newpassword ) & "`, " &_
" `" & fixQuotes( email ) & "`, " &_
" `" & fixQuotes( street ) & "`, " &_
" `" & fixQuotes( town ) & "`, " &_
" `" & fixQuotes( county ) & "`, " &_
" `" & fixQuotes( postcode ) & "`, " &_
" `" & cctype & "`, " &_
" `" & fixQuotes( ccnumber ) & "`, " &_
" `" & ccexpires & "`, " &_
" `" & fixQuotes( nccname ) & "`, " &_
")"
Con.Execute sqlString
============================================================
Any ideas please? Thanks in advance!
|
|
|
Here is what I suggest: Right after you build the SQL statement and before you execute it, place this code:
Response.Write(sql)
Response.End
Then open your databse in Access and copy and paste the SQL statement into a query window. Access will reformat your query and point out what is wrong with the statement.
|
|
|
|
|
Oh, and briefly looking at your SQL statement....you need to remove the comma that you have right before the closing ")". That may be your only problem.
|
|
|
|
|
Thanks for the reply. I eventually noticed that I had the extra comma at the end and managed to fix it. :D
But thanks for letting me know about:
"Then open your databse in Access and copy and paste the SQL statement into a query window. Access will reformat your query and point out what is wrong with the statement."
I didn`t know that. Thanks again!!
|
|
|
I also made a mistake with the ` which should have all been `. Don`t know why I did that, heehee. :D
|
|
|
maybe it's because the '. i got that problem few months ago and i tried to replace ' with chr(39) and i think it solved my problem. i hope this can help
|
|
|
oops sorry, i mean replace it with chr(34) -.-'
|
|
|
Hi there,
please check your inserting field, on the table design view, whether UNICODE COMPRESION is set to True , if so, just remove that and try to insert...
Will it help you ...as helped me..
Regards,
aS
|
|
|
hello there,
i saw that many people are having with the same statement, i am having the same, but i dont have any of the above mentioned error in syntax or suggested solutions.
here is my code, if anyone can take a look, please email me a suggested solution.
is this something to do with the read/write security settings on the database that i am using, if it is, how do i fix it.
thank you
<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("newteam.mdb")
MyConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("newteam.mdb") & ";" & _
"Persist Security Info=False")
'"Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
set username = Request.Form("username")
set password = Request.Form("password")
SQL = "Insert into Passwords(Username,Password) Values ('" & Username & "','" & Password & "')"
MyConn.Execute(SQL)
%>
<HTML>
<BODY>
<%
response.write(username & " " & password)
%>
</BODY>
</HTML>
|
|
|
|
|
|
|
|