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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO error, or is it? 1

Status
Not open for further replies.

madHatter1

Technical User
Feb 27, 2003
54
0
0
GB
Hello

I am getting the following error message when I click on the 'Submit' button of a form:

city = request.form("city") telephone = request.form("telephone") message = request.form("message")%>
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

/Valy.asp, line 275

This is where I have my INSERT INTO and wonder if this is where the error lies (it is the only INSERT INTO I have):


' this is where the information gets submitted to the db


DIM Conn,strConn,SQLstmt,RS
set Conn = server.createobject("adodb.connection")
strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/database/validation.mdb")

Conn.open strConn
SQLstmt = "INSERT INTO users (fullname,email,city,telephone,message)"

SQLstmt = SQLstmt & " VALUES ("

SQLstmt = SQLstmt & "'" & fullname & "',"
SQLstmt = SQLstmt & "'" & eMail & "',"
SQLstmt = SQLstmt & "'" & city & "',"
SQLstmt = SQLstmt & "'" & telephone & "',"
SQLstmt = SQLstmt & "'" & message & "',"
SQLstmt = SQLstmt & ")"

or, does the message at the beginning of the error message, that is, city = request.form("city") telephone = request.form("telephone") message = request.form("message")%>
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

suggest the error lies elsewhere?

Many thanks for your views.

hatter

 
Debug your sql statement. See this thread thread333-641011 .

Also, I don't know that this is such a great idea without colons seperating the statements:
city = request.form("city") telephone = request.form("telephone") message = request.form("message")%>
 
Hello Veep

Thanks for your thread link.

I have inserted

response.write(SQLstmt)
response.end

and typed in a few things in the form (something in each field). Clicking on 'Submit', all the type remained in the field (except for the type in the messsage field - that disappeared).

This is what was generated:


city = request.form("city") telephone = request.form("telephone") message = request.form("message")%> INSERT INTO users (fullname,email,city,telephone,message) VALUES ('Harry Evans','tttt@iaia.com','Acapulco','121212121212121','How are things out there!?',)

But I am not really any the wiser, except something might be wrong with message - but I'm not really sure.

hatter

 
This looks funny...
Code:
city = request.form("city") telephone = request.form("telephone") message = request.form("message")%>
Are you missing the open script &quot;<%&quot; ? Also like Veep said, you need colons or line breaks between these commands. Post, if you will, that portion of the script...
 
Thanks dmhirsch

This is the script which should insert the information from the fields into the database (where table has the name users and all the field names are the same as though below):

<%
' this is where the information finally gets submitted to the database

DIM Conn,strConn,SQLstmt,RS
set Conn = server.createobject(&quot;adodb.connection&quot;)
strConn = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;/database/validation.mdb&quot;)

Conn.open strConn

SQLstmt = &quot;INSERT INTO users (fullname,email,city,telephone,message)&quot;

SQLstmt = SQLstmt & &quot; VALUES (&quot;

SQLstmt = SQLstmt & &quot;'&quot; & fullname & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & eMail & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & city & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & telephone & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & message & &quot;',&quot;
SQLstmt = SQLstmt & &quot;)&quot;

response.write(SQLstmt)
response.end


Set RS = conn.execute(SQLstmt)
If err.number>0 then
response.write &quot;VBScript Errors Occured:&quot; & &quot;<P>&quot;
response.write &quot;Error Number=&quot; & err.number & &quot;<P>&quot;
response.write &quot;Error Descr.=&quot; & err.description & &quot;<P>&quot;
response.write &quot;Help Context=&quot; & err.helpcontext & &quot;<P>&quot;
response.write &quot;Help Path=&quot; & err.helppath & &quot;<P>&quot;
response.write &quot;Native Error=&quot; & err.nativeerror & &quot;<P>&quot;
response.write &quot;Source=&quot; & err.source & &quot;<P>&quot;
end if
IF conn.errors.count> 0 then
response.write &quot;Database Errors Occured&quot; & &quot;<P>&quot;
response.write SQLstmt & &quot;<P>&quot;
for counter= 0 to conn.errors.count
response.write &quot;Error #&quot; & conn.errors(counter).number & &quot;<P>&quot;
response.write &quot;Error desc. -> &quot; & conn.errors(counter).description & &quot;<P>&quot;
next
else
Response.Redirect(&quot;thankyouvisitor1.asp?updated=true&quot;)

end if
end if
end if
%>
 
The sql statement looks ok except you've got a comma trailing the last value 'How are things out there!?',)

You gotta clean up the rest of it though, get this stuff on seperate lines:
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
message = request.form(&quot;message&quot;)

and post a little more code so we can figure out why this: city = request.form(&quot;city&quot;) telephone = request.form(&quot;telephone&quot;) message = request.form(&quot;message&quot;)%> is showing up in your insert statement.
 
Hello to both of you again

OK, this is the bones of the code, minus some CDONTS and HTML stuff:

Incidentally, I am grateful to you both.

<%option explicit%>
<%DIM ErrorMsg, fullname,email,city,telephone,message%>
<%

const numFields = 5
dim errorArray()
redim preserve errorArray(numFields)

if request.form(&quot;isSubmitted&quot;) = &quot;yes&quot; then
fullname = request.form(&quot;fullname&quot;)
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
email = request.form(&quot;email&quot;)
message = request.form(&quot;message&quot;)


ErrorMsg = &quot;&quot;
dim re
set re = New RegExp



'Full Name

re.Pattern = &quot;^[^0-9\/><\.,\\!\^\$\*\+\?@#%&\(\);:\[\]\{\}=&quot;&quot;']+$&quot;

re.Global = True
re.IgnoreCase = True
errorArray(0) = re.Test(fullname)
if errorArray(0) then
errorArray(0)=False
else
errorArray(0) = True
ErrorMsg = &quot;Please type in your full name<br>&quot;
end if


'Email

re.Pattern = &quot;^\w+@\w+\.\w+&quot;
errorArray(1) = re.Test(email)
if errorArray(1) then
errorArray(1) = False
else
errorArray(1) = True
ErrorMsg = ErrorMsg & &quot;Please type in a valid email address<br>&quot;
end if


'Telephone

re.Pattern = &quot;^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$&quot;
errorArray(3) = re.Test(telephone)
if errorArray(3) then
errorArray(3) = False
else
errorArray(3) = True
ErrorMsg = ErrorMsg & &quot;Please type in your telephone number<br>&quot;
end if


'Message

If Len(Trim(message)) > 9 Then
errorArray(4) = False
else
errorArray(4) = True
ErrorMsg = ErrorMsg & &quot;Please type in your message<br/>&quot;
end if
end if

%>


<%
if ErrorMsg <> &quot;&quot; then %>
<font etc><%= ErrorMsg %> </font>
<%end if%>
<form name=&quot;sample1&quot; method=&quot;post&quot;>



'fullname

<% if errorArray(0) = True then %>
<font etc><% end if %>
<% if errorArray(0) = True then %>
</font>
<% end if %>


'email
<% if errorArray(1) = True then %>
<font etc>
<% end if %>
<% if errorArray(1) = True then %>
<% end if %>


'telephone
<% if errorArray(3) = True then %>
<font etc>
<% end if %>
<% if errorArray(3) = True then %>
<% end if %>


'message
<% if errorArray(4) = True then %>
<font etc>
<% end if %>
<% if errorArray(4) = True then %>
<% end if %>


<%if request.form(&quot;isSubmitted&quot;) = &quot;yes&quot; then%>



<%
DIM all,i
all=False
For i=0 to 4
all=all OR CBOOL(errorArray(i))
Next
If Not all Then

fullname = request.form(&quot;fullname&quot;)
email = request.form(&quot;email&quot;)%>
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
message = request.form(&quot;message&quot;)%>

<%


CDONTS goes here


code in my post above (which begins: &quot;' this is where the information finally gets submitted to the database&quot;) then follows.

Is it possible the arrays are not working? I have trying to renumber them....without success.

Thanks

Hatter
 
OK. What's going on here?
fullname = request.form(&quot;fullname&quot;)
email = request.form(&quot;email&quot;) [COLOR=ff0000]%>[/color]
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
message = request.form(&quot;message&quot;) [COLOR=ff0000]%>[/color]

also just for yucks let's see what's actually getting posted to this form. Put this up at the top:

dim objItem
for each objItem in request.form()
response.write(objItem & &quot; = &quot; & request.form(objItem) & &quot;<br>&quot;)
Next
response.end()

 
With this, veep,

<%DIM ErrorMsg, fullname,email,city,telephone,message,objItem%>
<%

for each objItem in request.form()
response.write(objItem & &quot; = &quot; & request.form(objItem) & &quot;<br>&quot;)
Next
response.end()

The page is completely blank. I've uploaded it and refreshed..........not a dicky bird!

hatter
 
But I'll remove the two %> which you have highlighted - thanks
 
No, when I remove the 2 %> (after email and message), I get an error message:

Microsoft VBScript compilation error '800a0400'

Expected statement

/Valy.asp, line 209

<%
^


Cheers

hatter
 
There's something that I'm not seeing because this should throw an error.
[COLOR=ff0000]<% 'start tag [/color]
DIM all,i
all=False
For i=0 to 4
all=all OR CBOOL(errorArray(i))
Next
If Not all Then

fullname = request.form(&quot;fullname&quot;)
email = request.form(&quot;email&quot;) [COLOR=ff0000]%> End Tag[/color]
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
message = request.form(&quot;message&quot;) [COLOR=ff0000]%> End Tag[/color]

[COLOR=ff0000]<% Start tag [/color]


As much as I hate to say it you're probably going to have to post the whole script.
 
This is the whole script (less HTML and CDONTS) Veep....warts and all:

(again, I am very grateful)

<%option explicit%>

<%DIM ErrorMsg, fullname,email,city,telephone,message%>
<%


const numFields = 5
dim errorArray()
redim preserve errorArray(numFields)

if request.form(&quot;isSubmitted&quot;) = &quot;yes&quot; then
fullname = request.form(&quot;fullname&quot;)
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
email = request.form(&quot;email&quot;)
message = request.form(&quot;message&quot;)


ErrorMsg = &quot;&quot;
dim re
set re = New RegExp



'Full Name

re.Pattern = &quot;^[^0-9\/><\.,\\!\^\$\*\+\?@#%&\(\);:\[\]\{\}=&quot;&quot;']+$&quot;
re.Global = True
re.IgnoreCase = True
errorArray(0) = re.Test(fullname)
if errorArray(0) then
errorArray(0)=False
else
errorArray(0) = True
ErrorMsg = &quot;Please type in your
full name<br>&quot;
end if





'Email
re.Pattern = &quot;^\w+@\w+\.\w+&quot;
errorArray(1) = re.Test(email)
if errorArray(1) then
errorArray(1) = False
else
errorArray(1) = True
ErrorMsg = ErrorMsg & &quot;Please type in a valid email address<br>&quot;
end if



'Telephone
'match phone numbers, allowing for an international dialing code at the start and hyphenation and spaces

re.Pattern = &quot;^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$&quot;
errorArray(3) = re.Test(telephone)
if errorArray(3) then
errorArray(3) = False
else
errorArray(3) = True
ErrorMsg = ErrorMsg & &quot;Please type in your telephone number<br>&quot;
end if



'Message
If Len(Trim(message)) > 9 Then
errorArray(4) = False
else
errorArray(4) = True
ErrorMsg = ErrorMsg & &quot;Please type in your message<br/>&quot;
end if


end if


%>

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>

</head>


<%
if ErrorMsg <> &quot;&quot; then %>
<%= ErrorMsg %> </font>
<%end if%>
<form name=&quot;sample1&quot; method=&quot;post&quot;>




'fullname

<% if errorArray(0) = True then %>
<% end if %>
<% if errorArray(0) = True then %>
<% end if %></td>



'email

<% if errorArray(1) = True then %>
<% end if %>
<% if errorArray(1) = True then %>
<% end if %></td>



'telephone

<% if errorArray(3) = True then %>
<% end if %>
<% if errorArray(3) = True then %>
<% end if %>



'message
<% if errorArray(4) = True then %>
<% end if %>
<% if errorArray(4) = True then %>
<% end if %>


<input type=&quot;text&quot; name=&quot;fullname&quot; value=&quot;<%= fullname %>&quot; class=&quot;txt&quot;>

<input type=&quot;text&quot; name=&quot;city&quot; value=&quot;<%= city %>&quot; class=&quot;txt&quot;>

<input type=&quot;text&quot; name=&quot;email&quot; value=&quot;<%=email %>&quot; class=&quot;txt&quot;>

<input type=&quot;text&quot; name=&quot;telephone&quot; value=&quot;<%= telephone %>&quot; class=&quot;txt&quot;>

<textarea class=&quot;txt&quot; name=&quot;message&quot; value=&quot;<%=message%>&quot; rows=&quot;5&quot; cols=&quot;19&quot;></textarea>


<p><input type=&quot;submit&quot; name=&quot;B1&quot; class=&quot;txt&quot; value=&quot;Submit&quot;
>

<input type=&quot;hidden&quot; name=&quot;isSubmitted&quot; value=&quot;yes&quot;>

<input type=&quot;reset&quot; name=&quot;clear&quot; class=&quot;txt&quot; value=&quot;Reset&quot;>


</form>

<%if request.form(&quot;isSubmitted&quot;) = &quot;yes&quot; then%>

<%
DIM all,i
all=False
For i=0 to 4
all=all OR CBOOL(errorArray(i))
Next
If Not all Then

fullname = request.form(&quot;fullname&quot;)
email = request.form(&quot;email&quot;)%>
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
message = request.form(&quot;message&quot;)%>

<%


<%

' this is where the information finally gets submitted to the database

DIM Conn,strConn,SQLstmt,RS
set Conn = server.createobject(&quot;adodb.connection&quot;)
strConn = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;/database/validation.mdb&quot;)

Conn.open strConn

SQLstmt = &quot;INSERT INTO users (fullname,email,city,telephone,message)&quot;

SQLstmt = SQLstmt & &quot; VALUES (&quot;

SQLstmt = SQLstmt & &quot;'&quot; & fullname & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & eMail & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & city & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & telephone & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & message & &quot;',&quot;
SQLstmt = SQLstmt & &quot;)&quot;

response.write(SQLstmt)
response.end


Set RS = conn.execute(SQLstmt)
If err.number>0 then
response.write &quot;VBScript Errors Occured:&quot; & &quot;<P>&quot;
response.write &quot;Error Number=&quot; & err.number & &quot;<P>&quot;
response.write &quot;Error Descr.=&quot; & err.description & &quot;<P>&quot;
response.write &quot;Help Context=&quot; & err.helpcontext & &quot;<P>&quot;
response.write &quot;Help Path=&quot; & err.helppath & &quot;<P>&quot;
response.write &quot;Native Error=&quot; & err.nativeerror & &quot;<P>&quot;
response.write &quot;Source=&quot; & err.source & &quot;<P>&quot;
end if
IF conn.errors.count> 0 then
response.write &quot;Database Errors Occured&quot; & &quot;<P>&quot;
response.write SQLstmt & &quot;<P>&quot;
for counter= 0 to conn.errors.count
response.write &quot;Error #&quot; & conn.errors(counter).number & &quot;<P>&quot;
response.write &quot;Error desc. -> &quot; & conn.errors(counter).description & &quot;<P>&quot;
next
else
Response.Redirect(&quot;thanks1.asp?updated=true&quot;)

end if
end if
end if
%>

 
fullname = request.form(&quot;fullname&quot;)
email = request.form(&quot;email&quot;)[COLOR=ff0000]%> remove this one [/color]
city = request.form(&quot;city&quot;)
telephone = request.form(&quot;telephone&quot;)
message = request.form(&quot;message&quot;)%>
**********************************
What's going on here? Is there a corresponding %> somewhere to close that first tag below? Is that where your CDONTS routine is? If not get rid of the red one.

message = request.form(&quot;message&quot;)%>

[COLOR=ff0000]<%[/color]


<%

' this is where the information finally gets submitted to the database

SQLstmt = SQLstmt & &quot;'&quot; & fullname & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & eMail & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & city & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & telephone & &quot;',&quot;
SQLstmt = SQLstmt & &quot;'&quot; & message & &quot;'[COLOR=ff0000],[/color]&quot; [COLOR=ff0000] Get rid of this comma[/color]
SQLstmt = SQLstmt & &quot;)&quot;
*********************************************
Change this line:
strConn = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;/database/validation.mdb&quot;)

To this:
strConn=&quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _
&quot;Data Source=&quot; & Server.MapPath(&quot;/database/validation.mdb&quot;) & &quot;;&quot; _
&quot;User Id=admin;&quot; & _
&quot;Password=&quot;

There's not a heck of a lot wrong here (that I can see) except some syntax stuff. BTW the reason that you didn't get anything by placing this:
for each objItem in request.form()
response.write(objItem & &quot; = &quot; & request.form(objItem) & &quot;<br>&quot;)
Next
at the top of the form is because the action doesn't begin to happen until your variable isSubmitted becomes &quot;Yes&quot; so the snippet would need to go below that line.
Good luck. ;-)



 
You've given me great help, Veep.
I have done this:

email = request.form(&quot;email&quot;)%> remove this one

but kept the other <% because it's part of CDONTS, and I have removed the , before the ) right bracket.

Tomorrow I'll work on your:

for each objItem in request.form()
response.write(objItem & &quot; = &quot; & request.form(objItem) & &quot;<br>&quot;)
Next

Many many thanks again for your time and your help.

hatter

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top