Forums

ASP

This topic is locked

One form - modify/insert

Posted 16 Feb 2005 17:38:37
1
has voted
16 Feb 2005 17:38:37 Chad Cullum posted:
I am trying to track user changes in an application. For every new record, update and delete, I want to perform the appropriate write of all fields to the table, but then I also want to insert all fields to a log table. I have tried hand-coding the insert/insert or update/insert code as appropriate with no luck - pretty sure I have massive variable issues.

So now I am thinking about doing the write to the table as normal, then pass form variable to another page and do the logfile write from there. However, I dont really need a confirmation page for all transactions. Can I pass these variables to the second page and automatically have it redirect as soon as the write is complete without user interaction?

Anyone have a more elegant solution?

Thx.

Replies

Replied 16 Feb 2005 18:45:51
16 Feb 2005 18:45:51 Simon Martin replied:
What DB and language?
Stored Procedures in SQL Server would do this nicely - do your insert set @@IDENTITY and use that to create the relationship when you insert into the log table.

Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
Replied 16 Feb 2005 19:12:24
16 Feb 2005 19:12:24 Chad Cullum replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
What DB and language?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Sorry - access db, dreamweaver mx, asp, vbscript

Replied 16 Feb 2005 19:50:48
16 Feb 2005 19:50:48 Simon Martin replied:
Have a look at InsertRecordWithIdent www.dmxzone.com/showDetail.asp?TypeId=3&NewsId=195
This handy little extension will do pretty much what i've described. There is an alternative extension by Tom Muck - but it costs (though it does have a bit more functionality)

The extension might throw up a js error - if you google for that there's the solution to the problem at the newman website

HTH

Live the life you love
Love the life you live
~ ~ ~ ~ ~ ~ ~
<b>Simon Martin</b> - <i>DMXzone Manager</i>
<font size=1>[ Dreamweaver MX/MX2004 | ASP | SQL | XHTML/CSS | Web Accessibility ] </font id=size1>
Replied 18 Feb 2005 19:28:56
18 Feb 2005 19:28:56 Chad Cullum replied:
I have started from scratch with a very basic app and I can get a modification form to UPDATE to one db (DATA) and INSERT via stored procedure to another DB (LOG).

The idea here was to log all changes that users might make. Now the problem I am facing is what data is being written to the LOG file. For example, a user selects the record for "John Doe" and get a page with a form to modify this record. They can update the First Name (fname) and/or Last Name (lname). When they submit the form, the new info (e.g. Jane Doe) is Updated in DATA. But the LOG gets the old info (John Doe).

This happens because that is the way it is coded:

<pre id=code><font face=courier size=2 id=code> &lt;%

if((rs_test_mod.Fields.Item("ID".Value) &lt;&gt; "" then Command1__intID = (rs_test_mod.Fields.Item("ID".Value)

if((rs_test_mod.Fields.Item("fname".Value) &lt;&gt; "" then Command1__strFname = (rs_test_mod.Fields.Item("fname".Value)

if((rs_test_mod.Fields.Item("lname".Value) &lt;&gt; "" then Command1__strLname = (rs_test_mod.Fields.Item("lname".Value)

%&gt;
&lt;%

set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_connLOG_STRING
Command1.CommandText = "INSERT INTO LOG (test_id, test_fname, test_lname) VALUES (" + Replace(Command1__intID, "'", "''" + ", '" + Replace(Command1__strFname, "'", "''" + "','" + Replace(Command1__strLname, "'", "''" + "') "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%&gt;</font id=code></pre id=code>

So my variable are set to be the values pulled from the recordset and those are being passed back to the LOG file. Instead, I want the variables to be set to the values entered in the form by the user.

For example, I changed the run-time value of the strFname variable from:
(rs_test_mod.Fields.Item("fname".Value)

to:
Request.Form("fname"

But the LOG file gets a blank for First Name. Hopefully I am close, but I dont understand how to get the user entered information to insert via my stored procedure. Apparently Request.Form("fname" isn't right...

Reply to this topic