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