ASP Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.11

hyBook - A Simple Guestbook Application

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13 

ASP Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

hyBook - Guestbook Application

Using MS Access Databases

ActiveX Data Object (ADO)

Controlling Response Header Lines

Microsoft Scripting Runtime DLL

Using Cookies

ASP Sessions

ASP Objects

Microsoft Script Debugger

Internet Information Services (IIS)

... Table of Contents

(Continued from previous part...)

Function doSubmit
'  Taking input values
   If Request.Form("Method") = "Post" Then
      hgRqParam.Add "Submit", myTrim(Request.Form("Submit"),10)
      hgRqParam.Add "ID", myTrim(Request.Form("ID"),6)
      hgRqParam.Add "TopicID", myTrim(Request.Form("TopicID"),6)
      hgRqParam.Add "Name", myTrim(Request.Form("Name"),40)
      hgRqParam.Add "Email", myTrim(Request.Form("Email"),40)
      hgRqParam.Add "Content", myTrim(Request.Form("Content"),2000)
      hgRqParam.Add "Timestamp", myTrim(Request.Form("Timestamp"),20)
      hgRqParam.Add "IpAddress", myTrim(Request.Form("IpAddress"),15)
      hgRqParam.Add "ItemID", myTrim(Request.Form("ItemID"),6)
   End If
   
'  Initial handling of submit
   If hgRqParam("Submit") = "Search" Then
      ' doNothing
   ElseIf hgRqParam("Submit") = "Clear" Then
      hgRqParam("ID") = ""
      hgRqParam("TopicID") = ""
      hgRqParam("Name") = ""
      hgRqParam("Email") = ""
      hgRqParam("Content") = ""
      hgRqParam("Timestamp") = ""
      hgRqParam("IpAddress") = ""
   ElseIf hgRqParam("Submit") = "Update" Then
      ' doNothing
   ElseIf hgRqParam("Submit") = "Insert" Then
      ' doNothing
   ElseIf hgRqParam("Submit") = "Select" Then
      doSelect
   ElseIf hgRqParam("Submit") = "Delete" Then
      doDelete
   Else 
      ' doNothing
   End If

'  Preparing values for HTML page
   aKeys = hgRqParam.Keys()
   For i=0 To hgRqParam.Count-1
      k = aKeys(i)
       hgPgParam.Add k, Server.HTMLEncode(hgRqParam(k))
   Next

'  Preparing values for Database
   aKeys = hgRqParam.Keys()
   For i=0 To hgRqParam.Count-1
      k = aKeys(i)
       hgDbParam.Add k, Replace(hgRqParam(k), "'", "''")
   Next

'  Final handling of submit
   If hgRqParam("Submit") = "Search" Then
      ' doNothing
   ElseIf hgRqParam("Submit") = "Clear" Then
      ' doNothing
   ElseIf hgRqParam("Submit") = "Update" Then
      doUpdate
   ElseIf hgRqParam("Submit") = "Insert" Then
      doInsert
   ElseIf hgRqParam("Submit") = "Select" Then
      ' doNothing
   ElseIf hgRqParam("Submit") = "Delete" Then
      ' doNothing
   Else 
      ' doNothing
   End If

   If bgDebug Then
      myDump
   End If
End Function

Function doSelect
   If hgRqParam("ItemID") = "" Then
      sgNotice = "No item selected."
   Else 
      Set rsComment = Server.CreateObject("ADODB.Recordset")
      sSQL = "SELECT * FROM hyComment WHERE ID=" & hgRqParam("ItemID")
      rsComment.Open sSQL, ogConn
      If rsComment.EOF Then
         sgNotice = "No record found."
      Else 
         hgRqParam("ID") = rsComment("ID")
         hgRqParam("TopicID") = rsComment("TopicID")
         hgRqParam("Content") = rsComment("Content")
         hgRqParam("Name") = rsComment("Name")
         hgRqParam("Email") = rsComment("Email")
         hgRqParam("Timestamp") = rsComment("Timestamp")
         hgRqParam("IpAddress") = rsComment("IpAddress")
      End If
   End If
End Function

Function doDelete
   If hgRqParam("ItemID") = "" Then
      sgNotice = "No item selected."
   Else 
      Set rsComment = Server.CreateObject("ADODB.Recordset")
      sSQL = "DELETE FROM hyComment WHERE ID=" & hgRqParam("ItemID")
      rsComment.Open sSQL, ogConn
      sgNotice = "Record deleted."
   End If
End Function

(Continued on next part...)

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13 

Dr. Herong Yang, updated in 2005
ASP Tutorials - Herong's Tutorial Notes - hyBook - A Simple Guestbook Application