In this example we'll see how a basic Guest Book. This is a very common addition to sites to get information on site reviews, shopping experiences and in some cases just for fun.
First thing we do is creating our form. Again just some basic HTML coding.
save this page as guest.htm
<html>
<body>
<form method="post" action="guest.asp">
<table>
<tr>
<td colspan="2"><strong>Please feel free to sign my guest book and let me know how the site is.</strong></td>
</tr>
<tr>
<td><strong>Enter your info here to sign</strong></td>
<tr>
<td> Email Address:</td>
<td><input type="text" name="EmailAddr"></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td>Comment my site:</td>
<td><input type="text" name="comments" size="60"></td>
</tr>
<tr>
<td><input type="submit" value="Submit" name="submit2"></td>
<td><input type="reset" value="Reset" name="reset"></td>
</tr>
</table>
</form>
</body>
</html>
Next we need to write our processing script which we named guest.asp in our form,
Step one is to create your connection and our recordset. Then we execute the sql statement to populate the recordset.
<%
dim cnn,rs
set cnn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.RecordSet")
cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("databases\guestbook.mdb")
sqltext = "SELECT * FROM tblguest"
rs.Open sqltext,cnn,3,3
Now we gather the users data from the form.
dim nm, addr, com, day
nm = Request.Form("Name")
com = Request.Form("comments")
addr = Request.Form("EmailAddr")
day = now
And lastly, we insert that data into the database
rs.AddNew
rs("Name") = nm
rs("EmailAddr") = addr
rs("Comments") = com
rs("Date") = day
rs.update
cnn.Close
Set rs=Nothing
Set cnn=Nothing
'Lets redirect the user to a page to view the results next
Response.Redirect "GuestEntries.asp"
%>
Name this page GuestEntries.asp
<%
' declare the variables
Dim Conn, dbpath
' create the connections and open them
Set Conn = Server.Createobject("ADODB.Connection")
dbpath ="DBQ=" & server.mappath("databases\guestbook.mdb")
Conn.open "DRIVER={Microsoft Access Driver (*.mdb)};" & dbpath
Dim rs, sqltxt
' create the recordset object
Set rs = Server.CreateObject("ADODB.Recordset")
'basic sql statement to select all the records fro each column in the table
sqltxt = "SELECT * FROM tblguest"
'fill the record set with the data
rs.open sqltxt, Conn
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.