Help - Search - Members - Calendar
Full Version: sql insert errors with Access and ASP
HTMLHelp Forums > Programming > Databases
eemorris
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!!!
Brian Chandler
You may not get much help here, because not so many people use ASP or Access. But the first thing to do is to print the completed SQL request that you are sending. You seem to be building it by concatenating bits in a variable called SQLINSERT, so before called the "execute" thing, echo the query by outputting something like

<p>Query: [SQLINSERT]

Don't know how to write that in ASP.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.