<% 'variables Dim objConn, dispfile 'objects Set objConn = Server.CreateObject("ADODB.Connection") '''''''''''''''''''''''''''''''' ' Connects to database ' '''''''''''''''''''''''''''''''' Function Connect() objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _ "Data Source=" & Server.Mappath("MyDb.mdb") & ";" End Function '''''''''''''''''''''''''''''''' ' Disconnect from database ' '''''''''''''''''''''''''''''''' Function Disconnect() objConn.Close Set objConn = Nothing End Function '''''''''''''''''''''''''''''''' ' Get info from all the users ' '''''''''''''''''''''''''''''''' Function listGuestBook() Dim objRS strSQL = "SELECT * FROM tbGuestbook ORDER BY ID DESC " Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open strSQL, objConn Do While Not objRS.EOF %>

<%=objRS.fields("Name")%>
<%=objRS.fields("Topic")%>
<% dispfile = "guestfiles/guest"& objRS.fields("ID") &".txt" displayFile() %>
<% objRs.MoveNext Loop End Function '''''''''''''''''''''''''''''''' ' Get a uniq id that we will use for making the file ' '''''''''''''''''''''''''''''''' Function getUniqID() strSQL = "SELECT * FROM tbGuestbook WHERE Name = '"& name &"' AND Topic = '"& title &"' " Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open strSQL, objConn getUniqID = objRS.fields("ID") End Function '''''''''''''''''''''''''''''''' ' Add to guestbook ' '''''''''''''''''''''''''''''''' Function addToGuestBook() Dim objRS strSQL = "INSERT INTO tbGuestbook (Name, Topic) VALUES ( '"& name &"', '"& title &"' )" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open strSQL, objConn,2,2 End Function '''''''''''''''''''''''''''''''' ' Methods for making files ' '''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''' ' This method make a file, and takes the filename as an argument ' '''''''''''''''''''''''''''''''' Function makeFile() Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.CreateTextFile(Server.MapPath(thefilename),true) f.write(content) f.close Set f=nothing Set fs=nothing End Function '''''''''''''''''''''''''''''''' ' This method display the data in a file ' '''''''''''''''''''''''''''''''' Function displayFile() Set fs=Server.CreateObject("Scripting.FileSystemObject") 'open the file Set f=fs.OpenTextFile(Server.MapPath(dispfile), 1) Response.Write(f.ReadAll) End Function %>