Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Frustrating Syntax error in INSERT INTO statement error

Status
Not open for further replies.

RhythmAddict112

Programmer
Jun 17, 2004
625
0
0
US
Hi all. I have no idea why I am getting this error. Ive checked and rechecked everything I can think of...The SQL statement prints fine....

Basically, I am trying to insert a few fields into an access database.

the code for the page is below, as is the response.write of the sql query

page:
Code:
<% @ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Form to database</title>
</head>
<body>
<%
'declare your variables
Dim name, pass, email, inst, city, st, position, currdate, user
Dim sConnString, connection, sSQL

' Receiving values from Form, assign the values entered to variables
user = Request.Form("user")
pass = Request.Form("pass")
email = Request.Form("email")
inst = Request.form("inst")
city = Request.form("city")
st = Request.form("st")
position  = Request.form("position")
Currdate = Now()





'declare SQL statement that will query the database
sSQL = "INSERT into users_tbl (user, pass, email, inst, city, st, position, dt) values ('" & _
user & "', '" & pass & "', '" & email & "','" & inst & "','" & city & "','" & st & "','" & position & "','" & CurrDate & "')"
 

'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Users.mdb")

'create an ADO connection object
Set connection = Server.CreateObject("ADODB.Connection")

'Open the connection to the database
connection.Open(sConnString)

'execute the SQL
connection.execute(sSQL)
response.write ssql
response.write "The form information was inserted successfully."

' Done. Close the connection object
connection.Close
Set connection = Nothing
%>
</body>
</html>

Response.write of the SQL:
Code:
INSERT into users_tbl (user, pass, email, inst, city, st, position, dt) values ('username', 'password', 'emailfield','company','city','nj','thisone','7/30/2004 12:38:58 AM')
Any help would be great! thank you in advance
 
Access DB dates must be in #'s not single quotes


INSERT into users_tbl (user, pass, email, inst, city, st, position, dt) values ('username', 'password', 'emailfield','company','city','nj','thisone',#7/30/2004 12:38:58 AM#)

[thumbsup2]DreX
aKa - Robert
 
May be user is the reserve word...put it around the []


-VJ
 
Dates won't insert when in wrong format.
Check if your date field is set to "standard date" (as required for your CurrDate, or if set to "Short date".
The SQL will fail in the latter case...

CHeers,
Andy
 
hey guys. I'm sorry for not posting the error - it was getting late last night. The error was "error in INSERT INTO statement" I did resolve it before I went to bed, however....by changing two things...1 - the "user" var. I changed it to name, I'm not sure if this was part of the problem as it did not work after doing just that. I guess position must be a reserved word, because after shortening that to just "pos" Everything worked without a hitch. Thank you everyone for your help - enjoy your friday!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top