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!

posting a reply in a forum

Status
Not open for further replies.

cheekynorton

Technical User
Jan 21, 2002
12
0
0
GB
Please can someone help?
I get the following error when clicking on the post reply button when trying to reply to a post within a forum.

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/Forum/files/post.asp, line 28, column 104
sql2 = "insert into messages (title, body, date_created, date_modified, user_id, parent_id) values ('" &
-------------------------------------------------------------------------------------------------------^

I can log into the forum, display the messages, view a single message but cannot reply.
I cant work out what is wrong with code.
Below is the code for post.asp page.
Any help would be appreciated

<%@LANGUAGE = &quot;VBSCRIPT&quot;%>

<%


if session(&quot;loggedin&quot;) = &quot;&quot; then
response.redirect(&quot;default.asp&quot;)
end if
%>

<%
if request(&quot;action&quot;) = &quot;insert&quot; then

Dim Conn, ConnString
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
ConnString = &quot;DRIVER={Microsoft Access Driver (*.mdb)};&quot; & _
&quot;DBQ=C:\inetpub\ Conn.Open(ConnString)

sql = &quot;select id from users where username = '&quot; & session(&quot;username&quot;) & &quot;'&quot;
Set RS = Conn.Execute(sql)
if len(request(&quot;parent_id&quot;)) > 0 then
PID = request(&quot;parent_id&quot;)
else
PID = 0
end if

sql2 = &quot;insert into messages (title, body, date_created, date_modified, user_id, parent_id) values ('&quot; &
request(&quot;title&quot;) & &quot;', '&quot; & request(&quot;body&quot;) & &quot;', &quot; & RS(&quot;id&quot;) & &quot;, '&quot; & now & &quot;', &quot; & PID &
&quot;)&quot;
Conn.Execute(sql2)

Conn.close
response.redirect(&quot;list.asp&quot;)

else
%>

<html>
<head>
<title>Forum</title>
<STYLE TYPE=&quot;text/css&quot;>
font { font-family:verdana }
a { color:00000 }
a:visited { color: 000000 }
.cell { font-size:14px ; color:black }
.title { font-family:arial ; font-size:16px ; line-height: 18px ; font-weight:bold; vertical-align:top }
</STYLE>
</head>
<body bgcolor=&quot;E3EEEE&quot;>

<form name=&quot;myForm&quot; action=&quot;post.asp&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;insert&quot;>
<input type=&quot;hidden&quot; name=&quot;parent_id&quot; value=&quot;<%=request(&quot;parent_id&quot;)%>&quot;>
<table width=&quot;450&quot;>
<tr>
<td bgcolor=&quot;19CBC5&quot; width=&quot;150&quot; class=&quot;title&quot;>Title:</td>
<td bgcolor=&quot;AAE4E2&quot;>
<input type=&quot;text&quot; name=&quot;title&quot; style=&quot;width:300&quot; size=&quot;20&quot;></td>
</tr>
<tr>
<td bgcolor=&quot;19CBC5&quot; valign=&quot;top&quot; class=&quot;title&quot;>Message:</td>
<td bgcolor=&quot;AAE4E2&quot;><textarea name=&quot;body&quot; rows=&quot;15&quot; cols=&quot;40&quot;></textarea></td>
</tr>
<tr>
<td bgcolor=&quot;19CBC5&quot; colspan=&quot;2&quot; align=&quot;center&quot;><input type=&quot;submit&quot;></td>
</tr>
</table>
</form>

</body>
</html>

<%end if%>
 
I think its because you forgot the single quote before the last &quot;)&quot; so it should be..

sql2 = &quot;insert into messages (title, body, date_created, date_modified, user_id, parent_id) values ('&quot; &
request(&quot;title&quot;) & &quot;', '&quot; & request(&quot;body&quot;) & &quot;', &quot; & RS(&quot;id&quot;) & &quot;, '&quot; & now & &quot;', &quot; & PID &
&quot;')&quot;



It happens to the best of us.
 
Hi Snow, thanks for the reply.

I did as you suggested but still get the following error

Error Type:
(0x80020009)
Exception occurred.
/Forum/files/post.asp, line 28

Do you have any more suggestions?

I took out a field date_modified, this is the following code with quote added at the end:-

sql2 = &quot;insert into messages (title, body, user_id, date_created, parent_id) values ('&quot; & request(&quot;title&quot;) & &quot;', '&quot; & request(&quot;body&quot;) & &quot;', &quot; & RS(&quot;id&quot;) & &quot;, '&quot; & now & &quot;', &quot; & PID & &quot;')&quot;
Conn.Execute(sql2)
 
cheekynorton,

Do you have single quotes in your body someplace? If so, replacee with each single quote with two single quotes, not a double quote.

Also, are you trying to insert a string into an integer field?


fengshui_1998
 
The single quote you added at the end actually looks out of place to me... the best way to debug SQL statements is to write them to the screen before they are executed. That allows you to see exactly what is being passed to the database.

Try this:

sql2 = &quot;insert into messages ([title], [body], user_id, date_created, parent_id) values ('&quot; & request(&quot;title&quot;) & &quot;', '&quot; & request(&quot;body&quot;) & &quot;', &quot; & RS(&quot;id&quot;) & &quot;, '&quot; & now & &quot;', &quot; & PID & &quot;)&quot;

Response.write(&quot;SQL is &quot; & sql2 & &quot;<br>&quot;)

Conn.Execute(sql2)
 
Maybe its
Single quote before &quot;PID&quot; as well, and also around rs(&quot;id&quot;)?? j\Juan is right about writing it to the screen to see what it looks like, that helps.

Good luck.

sql2 = &quot;insert into messages (title, body, user_id, date_created, parent_id) values ('&quot; & request(&quot;title&quot;) & &quot;', '&quot; & request(&quot;body&quot;) & &quot;', &quot; & RS(&quot;id&quot;) & &quot;, '&quot; & now & &quot;', '&quot; & PID & &quot;')&quot;
Conn.Execute(sql2)

 
Thanks for all your help but the code still wont work.
Ive tried all suggestions :(
 
Could you post the SQL statement that you have now as well as what it outputted to the screen when you Response.write it before you try to execute it? Is the error the same as what you originally posted? If not, please post the new error.
 
I was not use rs(&quot;id&quot;) i would open your connection and put rs(&quot;id&quot;) to a string then close your connection first then do the insert.

try this:

<%
StrID = rs(&quot;id&quot;)
'close connection

'open again.. for insert..

sql2 = &quot;insert into messages ([title], [body], [user_id], [date_created], [parent_id]) values ('&quot; & request(&quot;title&quot;) & &quot;', '&quot; & request(&quot;body&quot;) & &quot;', '&quot; & StrID & &quot;', '&quot; & now & &quot;', '&quot; & PID & &quot;')&quot;



%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top