Forums

ASP

This topic is locked

updating table problem

Posted 20 Jun 2003 15:01:23
1
has voted
20 Jun 2003 15:01:23 Richard Krawczak posted:
Hi There

Can’t seem to get a grip on things

This underneath pasted peace of code inserts first of all a new reply to a messageboard “reply “ table.

Next thing, a SELECT COUNT AS, counts all the reply’s in the “reply” table corresponding to the id of the parent table “posts”.
The outcome representing the updated total of responses to a message go into a variable called no_replies

The final block of code needs to update this new value into the no_replies field of the parent table “posts” so people can see the amount of response to a message.

The code works for a great part. The reply’s are created and the counting of the reply’s query give a good result. Only the updating of the new created value into the parent table is still a problem.

Who has any idea what could be the problem with my code??
If you can spare the time please take a brief look..
I ‘m most grateful

JJF


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/molk_conn.asp" -->
<%
Dim tel,reply_title,reply_name,reply_email,reply
tel=Request.Form("tel"
post_id=Request.Form("post_id"
reply_title=request.Form("reply_title"
reply_name=request.Form("reply_name"
reply_email=Request.Form("reply_email"
reply=Request.Form("reply"
%>
<%
sql ="INSERT INTO replies (post_id, reply_title, reply_name, reply_email, reply) VALUES ('"&post_id& "','" &reply_title& "','" & reply_name & "','" & reply_email & "','" & reply & "')"

set InsertRecords = Server.CreateObject("ADODB.Command"
InsertRecords.ActiveConnection = MM_molk_conn_STRING
InsertRecords.CommandText = sql
InsertRecords.CommandType = 1
InsertRecords.CommandTimeout = 0
InsertRecords.Prepared = true
InsertRecords.Execute()
%>
<%
Dim rs_count__MMColParam
rs_count__MMColParam = "1"
If (Request("post_id" <> "" Then
rs_count__MMColParam = Request("post_id"
End If
%>
<%
Dim rs_count
Dim rs_count_numRows

Set rs_count = Server.CreateObject("ADODB.Recordset"
rs_count.ActiveConnection = MM_molk_conn_STRING
rs_count.Source = "SELECT COUNT (reply_id) AS no_replies FROM replies WHERE post_id = " + Replace(rs_count__MMColParam, "'", "''" + " "
rs_count.CursorType = 0
rs_count.CursorLocation = 2
rs_count.LockType = 1
rs_count.Open()
rs_count.no_replies=no_replies

rs_count_numRows = 0
%>
<%
Dim rs_update__MMColParam
rs_update__MMColParam = "1"
If (Request.QueryString("post_id" <> "" Then
rs_update__MMColParam = Request.QueryString("post_id"
End If

%>
<%

set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_molk_conn_STRING
Command1.CommandText = "UPDATE posts SET no_replies= no_replies WHERE post_id=post_id "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>
<%
rs_count.Close()
Set rs_count = Nothing
%>

Reply to this topic