Need help updating a record (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


RogC -> Need help updating a record (1/30/2008 7:10:13)

I am updating a basic asp forum, which works, I have created and wonder if the following is possible.

I have added two fields in the topic list table in the database, one for the username (LastUSer) and one for the date (LastTime) in which the last reply to the post was updated.

The reply section works and creates a new record for the reply post in the reply, but I want to update the record in the topic list table so that the Last User and Last Time fields are updated with the appropiate details.

After posting the reply, in which the record is added, I have redirected to another page so that I can update the Topic table with the last updated details but I get the following message:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Extra ) in query expression '(ID = )'.

The code I use is:

<% ID=request("ID") %>
<% LASTUSER=request("LastUser") %>
<% LASTTIME=request("LastTime") %>
<%
Dim DataConn
Dim CmdUpdateRecord
Dim MYSQL

Set DataConn = Server.CreateObject("ADODB.Connection")
Set CmdUpdateRecord = Server.CreateObject("ADODB.Recordset")

DataConn.Open "DBQ=" & Server.Mappath("../database/forum.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

MYSQL = "SELECT Topic.* FROM Topic WHERE (ID = " & ID & ")"

CmdUpdateRecord.Open MYSQL, DataConn, 1, 3

CmdUpdateRecord.Fields("LastUser") = LASTUSER
CmdUpdateRecord.Fields("LastTime") = LASTTIME
CmdUpdateRecord.Update

CmdUpdateRecord.Close
Set CmdUpdateRecord = Nothing
DataConn.Close
Set DataConn = Nothing
%>

The LastUser and LastTime details are hidden fields that I have attached to the form.

Any Ideas?




rdouglass -> RE: Need help updating a record (1/30/2008 12:29:12)

Hi and Welcome to OutFront

quote:

expression '(ID = )'.


That kinda' indicates you're not picking up the Request("id"). Where exactly are you grabbing that from, the form?

quote:

...after posting the reply, in which the record is added, I have redirected to another page ...


Are you passing it somehow during that redirect?




RogC -> RE: Need help updating a record (1/30/2008 12:43:20)

I was using a hidden variable from the form, but after the record was added, I don't think the value was being carried through.

I have just read about Session Objects, and may be able to set a session variable to carry from the message board, through to this page after the form. The code itself works, as I put it on the reply page, but the record could be updated and then the user could have cancelled out of a reply and the data on the topic list would have been wrong.

I am going to give the sessions a try now I have read about them. Does this mean that I would call the information like so:

<% LASTUSER=Session("LastUser") %> instead of <% LASTUSER=request("LastUser") %> ?

Thanks for the reply




rdouglass -> RE: Need help updating a record (1/30/2008 13:00:13)

quote:

<% LASTUSER=Session("LastUser") %> instead of <% LASTUSER=request("LastUser") %>


Looks accurate to me.




RogC -> RE: Need help updating a record (1/30/2008 13:16:27)

I have tried it and it now works, It has taken me a day and a half to work it out, but at least in the end I have got it working.

Silly really as it was staring me in the face as I use a session variable to display the username whilst they are logged in!!! [:)]

I will visit this forum again if I have any problems, it has certainly been a big help, rdouglas I salute you, it was your comment about how the data was being passed which put me in the right direction.

Thanks again!!!

Rog




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625