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

syntax error in INSERT INTO

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
Greetings all..
Simple code to add message to a guestbook, but this won't work.. why??
Code:
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("guestbook.mdb")

Namn		= Request.Form("namn")
Epost		= Request.Form("epost")
Hemsida   	= Request.Form("hemsida")
Meddelande	= Request.Form("meddelande")
Ip          = Request.ServerVariables("REMOTE_ADDR")
Datum		= Now

Conn.Execute("Insert Into guestbook Name,Email,Homepage,Message,Date,Ip) values(Namn,Epost,Hemsida,Meddelande,Datum,Ip)")

Conn.Close
Set Conn = Nothing

Response.Redirect "index.asp"

I get the error:
Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/guestbook/index.asp, line 87


I know this code SHOULD work... cause I copied it =D
My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Think it should look more like this

Conn.Execute("Insert Into guestbook (Name,Email,Homepage,Message,Date,Ip) values(Namn,Epost,Hemsida,Meddelande,Datum,Ip)")

just a missing bracket Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
sorry for the confusion, but somehow a bracket got lost in cyberspace... unfortionately that wasn't the problem =/ My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
First, make a string to hold the SQL statement, makes it much easier to handle. Then try this:

strSQL = "INSERT INTO guestbook " &_
"(Name, Email, Homepage, Message, Date, IP) " &_
"VALUES " &_
"'" & Namn & "', '" & Epost & "', '"Hemsida"', " &_
"'" & Meddelande & "', '" & Datum & "', '" Ip "')"

Conn.Execute(strSQL)


BTW, perhaps using some type of Pig Latin isn't the best for your variable names? lol. Good luck... Darrell Mozingo
MCSA, A+, Network+, i-Net+, MOUS 2000 Master
 
Is the table in the guestbook.mdb called guestbook as well? Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Opps, forgot the "(" before the first quote after VALUES... ie:

"VALUES " &_
"('" & Namn & "'..... Darrell Mozingo
MCSA, A+, Network+, i-Net+, MOUS 2000 Master
 
I noticed that whilst trying to execute =)
and sorry for the missing translation :) it's not "Pig Latin", it's swedish =D

and I know both versions SHOULD work..
I wonder, is there anyplace I can look up the error codes?
like this one: Microsoft JET Database Engine error '80040e14' My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Technet maybe? technet.microsoft.com

Sorry about that, never saw Swedish writen :) Darrell Mozingo
MCSA, A+, Network+, i-Net+, MOUS 2000 Master
 
This is really puzzeling..
I can't possibly see what that problem is... not even if I copy code from another guestbook will it work!! =(
This is the entire page... you can view it at:
Perhaps I missed something, or did things in a foul order..?! I know shit 'about ASP I tell you all =) and I've forgotten most of the SQL (only took a minor course), but it's starting to comeback...

and yeah, I hope I didn't forget to translate anything =P

cheers all :)[thumbsup]

Code:
<% Response.Buffer = True %>
<HTML>
<HEAD>
<TITLE>Guestbook - malfunction</TITLE>
<link rel=&quot;stylesheet&quot; href=&quot;[URL unfurl="true"]http://130.240.201.142/bin/common.css&quot;>[/URL]
<script language=&quot;JavaScript&quot; src=&quot;[URL unfurl="true"]http://130.240.201.142/bin/common.js&quot;></script>[/URL]
</HEAD>
<BODY>
<table border=&quot;0&quot; width=&quot;450&quot; align=&quot;center&quot;>
<tr>
    <td id=&quot;head&quot; align=&quot;center&quot;>Guestbook</td>
</tr>
<tr>
    <td><a href=&quot;#post&quot;>Post a message</a>.</td>
</tr>
<tr>
    <td>&nbsp;</td>
</tr>
<tr>
    <td align=&quot;center&quot;>Posted messages:</td>
</tr>
<tr>
    <td>&nbsp;</td>
</tr>
<tr>
    <td><hr></td>
</tr>
<%
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;guestbook.mdb&quot;)
Set RS = Conn.Execute(&quot;Select * From guestbook order by Date desc&quot;)

RS.MoveFirst
Do While Not RS.EOF
    %>
    <tr>
        <td>
        <%If RS(&quot;Email&quot;) <> &quot;&quot; Then %><a href=&quot;mailto:<%=RS(&quot;Email&quot;)%>&quot;><%=RS(&quot;Name&quot;)%></a><%Else%><%=RS(&quot;Name&quot;)%><%End if%>
        <%If RS(&quot;Homepage&quot;) <> &quot;&quot; Then %> - <a href=&quot;<%=RS(&quot;Homepage&quot;)%>&quot; target=&quot;_new&quot;>Visit homepage</a><small></small><%End if%>
        - posted - <small>&lt;<%=FormatDateTime(RS(&quot;Date&quot;),1)%>&nbsp;Time:&nbsp;<%=FormatDateTime(RS(&quot;Date&quot;),4)%>&gt;</small><br>
        <i><%=RS(&quot;Message&quot;)%></i>
        </td>
    </tr>
    <tr>
        <td><hr></td>
    </tr>
    <%
    RS.MoveNext
Loop
RS.Close
Conn.Close
Set RS = Nothing
Set Conn = Nothing
%>
<tr>
    <td>&nbsp;</td>
</tr>
<tr>
    <td><a name=&quot;post&quot;></a>
    <form method=&quot;post&quot; action=&quot;index.asp?action=post&quot; name=&quot;gastbok&quot;>
        <input type=&quot;text&quot; name=&quot;Name&quot; value=&quot;John Doe&quot; size=&quot;25&quot;>
        <input type=&quot;text&quot; name=&quot;Email&quot; value=&quot;john.doe@microsoft.net&quot; size=&quot;25&quot;><br>
        <input type=&quot;text&quot; name=&quot;Homepage&quot; value=&quot;[URL unfurl="true"]http://www.hotmail.com&quot;[/URL] size=&quot;25&quot;><br>
        <textarea cols=&quot;52&quot; rows=&quot;5&quot; name=&quot;Message&quot;>Test junk message...just like microsoft</textarea><br>
    <input type=&quot;submit&quot; value=&quot;Rista in i grottan...&quot;>
    </form>
    </td>
</tr>
<tr>
    <td align=&quot;center&quot;>
<pre>Guestbook code and posted messages
(c)Copyright Martin G Broman 2002</pre>
    </td>
</tr>
</table>
<%If Request.QueryString(&quot;action&quot;) = &quot;post&quot; Then

Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;guestbook.mdb&quot;)

Name		= Request.Form(&quot;Name&quot;)
Email		= Request.Form(&quot;Email&quot;)
Homepage   	= Request.Form(&quot;Homepage&quot;)
Message	    = Request.Form(&quot;Message&quot;)
Ip          = Request.ServerVariables(&quot;REMOTE_ADDR&quot;)
aDate		= Now

Conn.Execute(&quot;Insert Into guestbook(Name,Email,Homepage,Message,Date,Ip) values(&quot;&name&&quot;,&quot;&Email&&quot;,&quot;&Homepage&&quot;,&quot;&Message&&quot;,&quot;&aDate&&quot;,&quot;&Ip&&quot;)&quot;)

Conn.Close
Set Conn = Nothing

Response.Redirect &quot;index.asp&quot;

End If %>
</BODY>
</HTML>
My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
You are forgetting single quotes
Its always a good idea to put your sql statement in a string, so you can write it to the page to see the problem, it will show your string on the page before the error is shown... I also like to do each value on a new line so its easier to add values, and see everything clearly..

Code:
strSQL = &quot;Insert Into guestbook &quot; _
& &quot;(Name,Email,Homepage,Message,Date,Ip)&quot; _
& &quot;VALUES (&quot; _ 
& &quot;'&quot; & name & &quot;',&quot; _
& &quot;'&quot; & Email & &quot;',&quot; _
& &quot;'&quot; & Homepage & &quot;',&quot; _
& &quot;'&quot; & Message & &quot;',&quot; _
& &quot;'&quot; & aDate & &quot;',&quot; _
& &quot;'&quot; & Ip & &quot;')&quot;

Response.Write(strSQL)

Conn.Execute(strSQL)


www.vzio.com
ASP WEB DEVELOPMENT



 
Also, if your date is a date/time field than Access likes to do things backwards and requires it to be surrounded by #'s instead of single quotes:
(using snowboardrs SQL)
Code:
strSQL = &quot;Insert Into guestbook &quot; _
& &quot;(Name,Email,Homepage,Message,Date,Ip)&quot; _
& &quot;VALUES (&quot; _ 
& &quot;'&quot; & name & &quot;',&quot; _
& &quot;'&quot; & Email & &quot;',&quot; _
& &quot;'&quot; & Homepage & &quot;',&quot; _
& &quot;'&quot; & Message & &quot;',&quot; _
& &quot;#&quot; & aDate & &quot;#,&quot; _
& &quot;'&quot; & Ip & &quot;')&quot;

Response.Write(strSQL)
Conn.Execute(strSQL)
Also, I believe Date is a reserved word in Access and therefore should not be used as a field name. A good rule of thumb is to never use anything as a fieldname that could also be a function, data type, or instruction.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
Now that I think about it, Tarwn is right about the Date in for the table name. That will give you another error after you fix the single quotes problem. www.vzio.com
ASP WEB DEVELOPMENT



 
I feel soo stupid... after finding out that the date thing was the actual and ONLY problem I did what ever I could to change it by changing variables, adding # removing ' etc... but I never checked the database... stupid o' me called the field by &quot;date&quot;... well.. cheers all

Now it's all working... sorry =D though it gave me a good laugh =) perhaps I should stick to swedish then these problems won't occur this often o) My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top