<%Option Explicit%> <% Dim Status, Password Response.Buffer = True STATUS = Request("STATUS") PASSWORD = Request("PASSWORD") %> <% If STATUS = "CHECKEM" Then If PASSWORD = "editme" THEN Session("PASSWORDACCESS") = "Yes" End If End If %> <% If Session("PASSWORDACCESS") <> "Yes" Then %> LINK Systems - Admin
LINK Systems Personnel Only

Link Systems Home Page
444 McNally Dr. Nashville, TN 37211
Phone 615-833-4168 Fax 615-834-1984
Copyright © 2002

<% Response.End %> <% End If %> <% ' Password OK start manipulating data. %> URL Links Database <% ' Based on example form www.asp101.com ' No error checking so there are a number of places where this ' script could easily throw errors if you give it invalid input. ' Declare our standard variables. Dim iRecordId ' Used to keep track of the record in play strDbTable="tblUrlList" ' Choose what to do by looking at the action parameter Select Case LCase(Trim(Request.QueryString("action"))) Case "blank" ' Part 1 of 2 for adding a new record. Open blank form. %>

<%=strDBTable%>

Note: Watch your input... the text field is small and no error handling is done to check for dates. If an error gets thrown when you submit simply hit back and fix the offending entry before resubmitting.

<%' ? Would be nice to handle this Select by code.%>



Active   Inactive
<% Response.Write(RecordListing) Case "insert" ' Part 2 of 2 for adding a new record. Insert from form. OpenConnection() strSQL = "INSERT INTO " & strDbTable _ & " (fUrlClass,fUrlLink,fUrlText,fUrlDateEntered,fUrlActive)" & " VALUES ("_ & chr(39) & Request.Form("fUrlClass") & chr(39) & ","_ & chr(39) & Request.Form("fUrlLink") & chr(39) & ","_ & chr(39) & Request.Form("fUrlText") & chr(39) & ","_ & chr(35) & Request.Form("fUrlDateEntered") & chr(35) & ","_ & Request.Form("fUrlActive") & ")" ' chr(34) " for Access ' chr(35) # for Access dates ' chr(39) ' for Access ' Response.Write(strSQL) ' Debugging line rstLink.Open strSQL, cnnLinkDB, 3, 3 Response.Write("

Record added!

") Response.Write(RecordListing) ' Don't use CloseConnection() Case "delete" ' Get the id to delete iRecordId = Request.QueryString("fUrlId") If IsNumeric(iRecordId) Then iRecordId = CLng(iRecordId) Else iRecordId = 0 End If OpenConnection() strSQL = "DELETE FROM " & strDbTable & " WHERE fUrlId=" & iRecordId & ";" rstLink.Open strSQL, cnnLinkDB, 3, 3 Response.Write("

Record Id #" & iRecordId & " deleted!

") Response.Write(RecordListing) ' Don't use CloseConnection() Case "edit" ' First of a 2 part process... build a form with the values from the db. iRecordId = Request.QueryString("fUrlId") If IsNumeric(iRecordId) Then iRecordId = CLng(iRecordId) Else iRecordId = 0 End If OpenConnection() strSQL = "SELECT * FROM " & strDbTable & " WHERE fUrlId=" & iRecordId & ";" rstLink.Open strSQL, cnnLinkDB, 3, 3 If Not rstLink.EOF Then %>

<%=strDBTable%>

Note: Watch your input... the text field is small and no error handling is done to check for valid integers or dates. If an error gets thrown when you submit simply hit back and fix the offending entry before resubmitting.

" /> " />
" />
" />
" />
" />
<% Else Response.Write "Record not found!" End If Response.Write(RecordListing) ' Don't use CloseConnection() Case "editsave" ' Part 2 of 2: Here's where we save the values that the ' user entered back to the DB. Again... no error ' handling or input checking so ' characters and invalid ' values will throw error messages. iRecordId = Request.Form("fUrlId") OpenConnection() strSQL = "UPDATE " & strDbTable & " SET "_ & "fUrlClass = " & chr(39) & Request.Form("fUrlClass") & chr(39) & ", "_ & "fUrlText = " & chr(39) & Request.Form("fUrlText") & chr(39) & ", "_ & "fUrlLink = " & chr(39) & Request.Form("fUrlLink") & chr(39) & ", "_ & "fUrlDateEntered = " & chr(35) & Request.Form("fUrlDateEntered") & chr(35) & ", "_ & "fUrlActive = " & Request.Form("fUrlActive") & " "_ & "WHERE (fUrlId = " & iRecordId & ")" ' Response.Write(strSQL) ' Debugging line ' If something does throw an error, checking this is ' actually a valid command often helps debug. rstLink.Open strSQL, cnnLinkDB, 3, 3 ' Don't use CloseConnection() Response.Write("

Record Id #" & iRecordId & " updated!

") Response.Write(RecordListing) Case Else ' view ' Our default action... just lists the records in the DB dim ColorChanger, bgcolor, datatype 'Set alternating colors colorchanger=1 bgcolor="#ccffff" OpenConnection() strSQL = "SELECT * FROM " & strDbTable & " ORDER BY fUrlClass,fUrlText " rstLink.Open strSQL, cnnLinkDB, 3, 3 %> <% Do While Not rstLink.EOF ' Create alternating color backgrounds. if colorchanger=1 then datatype="DataOdd" colorchanger=0 elseif colorchanger=0 then datatype="DataEven" colorchanger=1 end if %> <% rstLink.MoveNext Loop %>
<%=strDbTable%>
Add a new record
Class Text Active    
<%= rstLink.Fields("fUrlClass").Value %> <%= rstLink.Fields("fUrlText").Value %> <%= rstLink.Fields("fUrlActive").Value %> ">Delete ">Edit
<% Response.Write rstLink.RecordCount %> Total Records
<% ' This one should be okay (always come back here last.). CloseConnection() End Select %>