Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Syntax error in INSERT INTO statement
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Syntax error in INSERT INTO statement

 Post Reply Post Reply
Author
wolfie View Drop Down
Groupie
Groupie


Joined: 18 November 2002
Location: United Kingdom
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote wolfie Quote  Post ReplyReply Direct Link To This Post Topic: Syntax error in INSERT INTO statement
    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--[ WolfWeb.co.uk ]
PHP, .net--[ beginner ] ASP, VB, C, SQL--[ intermediate ] X/D/HTML, CSS, WML, XML--[
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
wolfie View Drop Down
Groupie
Groupie


Joined: 18 November 2002
Location: United Kingdom
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote wolfie Quote  Post ReplyReply Direct Link To This Post 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--[ WolfWeb.co.uk ]
PHP, .net--[ beginner ] ASP, VB, C, SQL--[ intermediate ] X/D/HTML, CSS, WML, XML--[
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.