Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 8th, 2006, 03:10 PM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare "before and after" values on a form?

Hello all,

I am working on an ASP web interface that allows some of our employees to view and update information retrieved from a Foxpro for Windows 2.6 (.DBF) database.

Part of the business rules requirement is that I log (into the database) any changes which occur. e.g. if someone changes a client's username it would say "Username changed from [old value] to [new value]". I'm running into a problem when I try to create this log string to pass to the data update; the variables I declare to hold the database values are lost when the page is submitted, and so it ALWAYS writes the log file (since the new value has something and the old one is null).

Here is a snippet of the relevant code:
Code:
    Dim strSchoolCode       ' School Code
    Dim strUserName         ' Admin's username
    Dim strPassword         ' Admin's password
    Dim strName             ' Admin's full name
    Dim strSubDate          ' Subscription date
    Dim strExpDate          ' Expiration Date
    Dim strEmail            ' Email address
    Dim blnPrimaryAdmin     ' Primary admin (T/F)

    '-----------------------------
    ' CODE TO RETRIEVE VALUES 
    '-----------------------------
    Dim cnnValidDB          ' ADODB.Connection object
    Dim rstAdmin            ' ADODB.Recordset object
    Dim strSQL              ' SQL statement

    strSchoolCode = Trim(Request.QueryString("school"))

    strUserName = Trim(Request.QueryString("user"))

    strSQL = "SELECT * FROM Valid WHERE Schoolcode='" & strSchoolCode & "' AND User_name='" & strUserName & "'"

    Set cnnValidDB = Server.CreateObject("ADODB.Connection")

    cnnValidDB.Open "FILEDSN=directory_users.dsn"

    Set rstAdmin = cnnValidDB.Execute(strSQL)

    If Not rstAdmin.EOF Then
        strName = Trim(rstAdmin("Name"))
        strPassword = Trim(rstAdmin("Password"))
        strSubDate = Trim(rstAdmin("sub_date"))
        strExpDate = Trim(rstAdmin("exp_date"))
        strEmail = Trim(rstAdmin("Email"))
        blnPrimaryAdmin = CBool(rstAdmin("Main"))
    End If

    If Request.Form("updateButton") = "Update Information" Then
    ' Update the information in the database

        Dim strNewUserName
        Dim strNewName
        Dim strNewPassword
        Dim strNewSubDate
        Dim strNewExpDate
        Dim strNewEmail
        Dim blnNewPrimaryAdmin

        strNewUserName = Trim(Request.Form("userName"))
        strNewName = Trim(Request.Form("contactName"))
        strNewPassword = Trim(Request.Form("newPassword"))
        strNewSubDate = Trim(Request.Form("subdate"))
        strNewExpDate = Trim(Request.Form("expDate"))
        strNewEmail = Trim(Request.Form("emailAddress"))
        blnNewPrimaryAdmin = CBool(Request.Form("primaryAdminCheckBox"))

    ' Create text logging any changes to the data
        Dim temp_msg      
        Dim log

        If strUserName <> strNewUserName Then
            temp_msg = temp_msg & "Username changed from " & strUserName & " to " & strNewUserName & ".  "
        End If

        If strNewPassword <> "" And strPassword <> strNewPassword Then
            temp_msg = temp_msg & "Password changed from " & strPassword & " to " & strNewPassword & ".  "
        End If

        If strName <> strNewName Then
            temp_msg = temp_msg & "Name changed from " & strName & " to " & strNewName & ".  "
        End If

        If strSubDate <> strNewSubDate Then
            temp_msg = temp_msg & "Subscription Date changed from " & strSubDate & " to " & strNewSubDate & ".  "
        End If

        If strExpDate <> strNewExpDate Then
            temp_msg = temp_msg & "Expiration date changed from " & strExpDate & " to " & strNewExpDate & ".  "
        End If

        If strEmail <> strNewEmail Then
            temp_msg = temp_msg & "Email address changed from " & strEmail & " to " & strNewEmail & ".  "
        End If

        If blnPrimaryAdmin <> CBool(Request.Form("primaryAdminCheckBox")) Then
            temp_msg = temp_msg & "Primary administrator status changed from " & blnPrimaryAdmin & " to " & CBool(Request.Form("primaryAdminCheckBox")) & ".  "
        End If

        If temp_msg <> "" Then
            log = Date() &  " - " & Time() & " -- " &  temp_msg
        End If


        ' For debugging, just write out the contents of log
        Response.Write log
    End If
I need to be able to capture the data contained from the database and then check it behind the scenes against the new values; if any values are different then I need to log it. I know how to do this in ASP.NET but we can't use that (the hosting server is NT 4.5 Small Business with IIS 4.0; I don't even think .NET will install on that) and I am not really familiar with "Classic" ASP's working or with VBScript (my ASP.NET language of choice is C#, although I know enough VB.NET to work in that, too. Very different from VBScript, however...).

How could I go about doing this? I've tried writing to a cookie, but since the cookie is written to when the page loads the values are overwritten with the newer ones and the log never gets fired. Should I simply break that logic off into a seperate file with public variables?

Many thanks in advance for assistance,
Wayne

 
Old May 14th, 2006, 11:29 PM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

where is the form code? are you submitting to itself ("postback")?
it's assumed so because of the request.form code; however, ...where's the update code? is your form using hidden variables for the data or does the form use the database data in the input box "value"?

i may be overlooking it but it seems more input from you is needed

 
Old May 15th, 2006, 08:20 AM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry.. yes, the values are taken from the database when the page loads and inserted into the "value" attrib. of the input element. i haven't written the UDATE query yet; I've been experimenting with the request to determine how to capture the before values of the form so I don't lose then on postback.

 
Old May 17th, 2006, 03:13 AM
Authorized User
 
Join Date: Mar 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Wayne,

It doesn't make sense. It should work.

I take it that the code you sent is server side code (between <% %>).

I would do this: Add the following code after the lines:

If Not rstAdmin.EOF Then
        strName = Trim(rstAdmin("Name"))
        strPassword = Trim(rstAdmin("Password"))
        strSubDate = Trim(rstAdmin("sub_date"))
        strExpDate = Trim(rstAdmin("exp_date"))
        strEmail = Trim(rstAdmin("Email"))
        blnPrimaryAdmin = CBool(rstAdmin("Main"))
    End If

'Debug
Response.Write ("Name " & strName)
Response.Write ("Password " & strPassword)
Response.End

And check that the read from the DB is successful.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare values in different nodes fann XSLT 9 September 11th, 2008 06:25 AM
How to compare two lat/long values chandup SQL Server 2000 1 May 17th, 2007 05:07 AM
compare values in one row to the next tholleran SQL Server 2000 7 March 22nd, 2007 04:45 PM
compare the values in a select box ayse1st BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 January 7th, 2006 03:58 PM
Compare values of several drop boxes, notify user SoC Javascript How-To 1 April 21st, 2005 10:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.