INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Form Handling

Your First Form using ASP Processing by onpnt
Posted: 16 May 04

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

'write our headings for the table out
Response.Write "<P><TABLE>" & vbCrLf
Response.Write "<TR>" & vbCrLf
Response.Write "<TD BGCOLOR=""#F5F5F5""><B>Name</B></TD>" & vbCrLf
Response.Write "<TD BGCOLOR=""#F5F5F5""><B>Comments</B></TD>" & vbCrLf
Response.Write "<TD BGCOLOR=""#F5F5F5""><B>Email Address</B></TD>" & vbCrLf
Response.Write "<TD BGCOLOR=""#F5F5F5""><B>Date</B></TD>" & vbCrLf
Response.Write "</TR>" & vbCrLf

'loop until there are no more records to find
Do While Not rs.EOF
Response.Write "<TR>" & vbCrLf
Response.Write "<TD>" & rs("Name").Value & "</TD>" & vbCrLf
Response.Write "<TD>" & rs("comments").Value & "</TD>" & vbCrLf
Response.Write "<TD>" & rs("EmailAddr").Value & "</TD>" & vbCrLf
Response.Write "<TD>" & rs("Date").Value & "</TD>" & vbCrLf
Response.Write "</TR>" & vbCrLf
rs.MoveNext
Loop
Response.Write "</TABLE>" & vbCrLf
Conn.Close
Set rs=Nothing
Set Conn=Nothing
%>

Back to Microsoft: ASP (Active Server Pages) FAQ Index
Back to Microsoft: ASP (Active Server Pages) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close