Print Page | Close Window

Syntax error in INSERT INTO statement

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1891
Printed Date: 29 March 2026 at 8:32am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Syntax error in INSERT INTO statement
Posted By: wolfie
Subject: Syntax error in INSERT INTO statement
Date Posted: 18 April 2003 at 3:33am

Okay, I am hacking a sciprt that works like a guestbook system, but is really just a tag board. Now I am having a problem sending the information off too the database, I keep on getting the following error

----------------------------------------------------
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
/wolfsweb/shouts.app.asp, line 125
----------------------------------------------------

Here is the scirpt it happenes on (minus the HTML header and footer)...

----------------------------------------------------
      <%
Flag = request.form("Flag")
If IsEmpty(Flag) or Flag = "" then
%>
      <form action="/wolfsweb/shouts.app.asp" method="post">
        <p>
        <input type="text" name="Message" maxlength="120" size="23" class="box" onfocus="if(this.value=='message')this.value=''; this.style.background='#006060';" onblur="if(this.value=='')this.value='message'; this.style.background='#007575';" rows="1" cols="20" value="message"><br>
        <input type="text" name="URL" maxlength="120" size="23" value="website" class="box" onfocus="if(this.value=='website')this.value='http://'; this.style.background='#006060';" onblur="if(this.value=='http://')this.value='website'; this.style.background='#007575';"><br>
        <input type="text" name="Name" maxlength="20" size="14" value="name" class="box" onfocus="if(this.value=='name')this.value=''; this.style.background='#006060';" onblur="if(this.value=='')this.value='name'; this.style.background='#007575';">&nbsp;
        <input class="tonOff" onMouseOver="hoverTon(this);" onMouseOut="offTon(this);" type="submit" value=" post " name="submit"></p>
  <input type="hidden" name="Flag" value=1>
      </form>

<%
End If
If Flag = 1 then
 If IsEmpty(request.form("Name")) or request.form("Name")="name" or request.form("Name")=" " then
  response.write "<p class=""center"">"
  response.write "You must enter a name.<form>"
  response.write "<br>"
  response.write "<input class=""tonOff"" onMouseOver=""hoverTon(this);"" onMouseOut=""offTon(this);"" type=""button"" value=""Retry"" onclick=""history.back()"">"
  response.write "</form></p>"
  response.end
 Else
  Name = request.form("Name")
 End If

  If request.form("URL")="website" or request.form("URL")=" " then
     URL = ""
  Else
     URL = request.form("URL")
  End If
  
 If IsEmpty(request.form("Message")) or request.form("Message")="message" or request.form("Message")=" " then
  response.write "<p class=""center"">"
  response.write "Don't forget to enter your comments!<form>"
  response.write "<br>"
  response.write "<input class=""tonOff"" onMouseOver=""hoverTon(this);"" onMouseOut=""offTon(this);"" type=""button"" value=""Retry"" onclick=""history.back()"">"
  response.write "</form></p>"
  response.end
 Else
  Comments = request.form("Message")
  Comments = Replace(Message, Chr(34), "''")
  Comments = Replace(Message, vbCrLf, "<br>")
 End If
 Flag = request.form("Flag")

%>

<form action="/wolfsweb/shouts.app.asp" method="post"><p class="center"><small>"<%= Message %>"</small><br>
<input type="hidden" name="Message" value="<%= Message %>">
<input type="hidden" name="URL" value="<%= URL %>">
<input type="hidden" name="Name" value="<%= Name %>">
<input class="tonOff" onMouseOver="hoverTon(this);" onMouseOut="offTon(this);" type="submit" value="submit, <%= Name %>?"></p>
<input type="hidden" name="Flag" value=2></form>

<%
End If
If Flag = 2 then
 Today = Now()
 Comments = request.form("Message")
 Comments = Replace(Message, "'", "''")
 URL = request.form("URL")
 Name = request.form("Name")
  Name = Replace(Name, "'", "''")
  Name = Replace(Name, Chr(34), "''")

 ' ok now we've got our data so let's ship it off to the database
 set conn = server.createobject("adodb.connection")
 DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
    DSNtemp=dsntemp & "DBQ=" & server.mappath("/wolfsweb/db/wolfweb.mdb")
    conn.Open DSNtemp
 
 SQLstmt = "INSERT INTO Shout (Message,URL,Name)"
 SQLstmt = SQLstmt & " VALUES ("
 SQLstmt = SQLstmt & "'" & Message & "',"
 SQLstmt = SQLstmt & "'" & URL & "',"
 SQLstmt = SQLstmt & "'" & Name & "',"
 SQLstmt = SQLstmt & ")"
 
 Set RS = conn.execute(SQLstmt)
 If err.number>0 then
     response.write "VBScript Errors Occured:" & "<P>"
     response.write "Error Number=" & err.number & "<P>"
     response.write "Error Descr.=" & err.description & "<P>"
     response.write "Help Context=" & err.helpcontext & "<P>"
     response.write "Help Path=" & err.helppath & "<P>"
     response.write "Native Error=" & err.nativeerror & "<P>"
     response.write "Source=" & err.source & "<P>"
     response.write "SQLState=" & err.sqlstate & "<P>"
    end if
    IF conn.errors.count> 0 then
     response.write "Database Errors Occured" & "<P>"
     response.write SQLstmt & "<P>"
     for counter= 0 to conn.errors.count
      response.write "Error #" & conn.errors(counter).number & "<P>"
      response.write "Error desc. -> " & conn.errors(counter).description & "<P>"
     next
    else
     response.write "<p class=""center"">Submitted</p>"
    end if
    Conn.Close
 Set conn = nothing
End If
%>

----------------------------------------------------

Now, I can't for the life of me figure out where it's gone wrong and it's doing my head in. I spent 3 hours last night just looking around the code to figure out where it's gone wrong.
I'll give the orginal from where I am hacking it from to help...

----------------------------------------------------
<%
Flag = request.form("Flag")
If IsEmpty(Flag) or Flag = "" then
%>
<font face="times new roman">
<i><h1>Sign My Guestbook</h1></i>
 <font face="arial" size=2>
  <b><i>Note:</i> * indicates a required field</b><

-------------
Wolfie--[ http://www.wolfweb.co.uk - WolfWeb.co.uk ]
PHP, .net--[ beginner ] ASP, VB, C, SQL--[ intermediate ] X/D/HTML, CSS, WML, XML--[




Replies:
Posted By: MorningZ
Date Posted: 18 April 2003 at 6:50am
Take this chunk, add the line and inspect the SQL string to see where your code is messed up

SQLstmt = "INSERT INTO Shout (Message,URL,Name)"
SQLstmt = SQLstmt & " VALUES ("
SQLstmt = SQLstmt & "'" & Message & "',"
SQLstmt = SQLstmt & "'" & URL & "',"
SQLstmt = SQLstmt & "'" & Name & "',"
SQLstmt = SQLstmt & ")"

Response.Write SQLstmt
Response.End


Set RS = conn.execute(SQLstmt)

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: wolfie
Date Posted: 18 April 2003 at 6:58am

Yeah, I was meant to say that I solved the problem; somebody pointed out there was an extra "," in the last line that needed to be gotten rid of.

Also, that line you gave me
  Response.Write SQLstmt
  Response.End

is not needed. Though I do want to get rid of the last few lines because to me, they don't seem like they do anything.



-------------
Wolfie--[ http://www.wolfweb.co.uk - WolfWeb.co.uk ]
PHP, .net--[ beginner ] ASP, VB, C, SQL--[ intermediate ] X/D/HTML, CSS, WML, XML--[


Posted By: Bunce
Date Posted: 19 April 2003 at 2:37am

If you'd used those two lines that Morningz gave you, then you would have easily been able to spot what the problem was yourself.

It is the *first* thing to do when you have a database related error, as it will display on screen exactly what you are trying to send to the database.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net