Hi,
I'm pretty new to ASP and I'm trying to figure out how to send data from an HTML form to an Access database. Here is the .asp file I'm using:
<%
' Declaring variables
Dim firstname, lastname, company, phone, email, data_source, con, sql_insert
' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function
' Receiving values from Form
firstname = ChkString(Request.Form("firstname"))
lastname = ChkString(Request.Form("lastname"))
company = ChkString(Request.Form("company"))
phone = ChkString(Request.Form("phone"))
email = ChkString(Request.Form("email"))
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("TREAgents.mdb")
SQLINSERT="INSERT INTO TRE1 (First Name, Last Name, Company, Phone, Email) "
SQLINSERT=SQLINSERT & "VALUES ("
SQLINSERT=SQLINSERT & "'" & firstname & "', "
SQLINSERT=SQLINSERT & "'" & lastname & "', "
SQLINSERT=SQLINSERT & "'" & company & "', "
SQLINSERT=SQLINSERT & phone & ", "
SQLINSERT=SQLINSERT & "'" & email & "') "
' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute SQLINSERT
' Done. Close the connection
con.Close
Set con = Nothing
%>
However, I keep getting the following error:
Microsoft JET Database Engine error '80040e14'
Syntax error in INSERT INTO statement.
/form_ac.asp, line 35
So, I think the connection is fine, but there is obviously a problem with the SQLINSERT. Any ideas where I'm going wrong? Thanks in advance!!!