Shoutbox tutorial

3.1.2006, 17:16
Submited in: Asp | Total Views: 52842

This tutorial will show you how to make an easyest, known as shoutbox, and how to connect to access database, see data and write data over a form.

Shoutbox works on this principle: a visitor writes a name and a message, over a form.
Then all gets proceeded on to the page where we write all of the data down in the database.
After that we return on to the page where we have form for the inscription and where we can view shoutbox messages.

The page that will carrey form for the inscription, and messages will be shown, we’ll call shoutbox.asp.
The page on which we connect to the database common.asp., and the page where we inscript data in the database upis.asp.

Let us get started in this order.

First we’ll make a database. The database will be Microsoft Access.
Open Ms access, which you have in the office package, click on the Create table in design view.
We need to make fields in the table that we will call tblshoutbox.

ID - Auto Number
Name – Text
Mmmessage – Memo

After we finish, we will save the database as db.mdb

common.asp file (connect to access database)

'Dimension variables
Dim adocon
Dim strcon
Dim strSql
Dim rsShow
Dim rsAdd

'Create an ADO connection object
Set adocon = Server.CreateObject("ADODB.Connection")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb")


<!--#include file="common.asp" -->



Set rsShow = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT TOP 15 * FROM tblShoutbox ORDER BY ID DESC;"
rsShow.Open strSQL, strcon

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="16%">
Do while not rsShow.EOF
    <td width="100%"><b><% = rsShow("Name") %></b>-<% = rsShow("Msg") %></td>

<form method="POST" action="add.asp">
  <input type="text" name="name" size="20"><br>
  <input type="text" name="msg" size="20"><br>
  <input type="submit" value="  Submit  " name="submit"></p>

'Reset server objects
Set rsShow = Nothing
Set adocon = Nothing

And in the end add.asp, where the data received from the form will be inscribed into the database.

<!--#include file="common.asp" -->

'Create an ADO recordset object
Set rsAdd = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT tblShoutbox.* FROM tblShoutbox;"
rsAdd.CursorType = 2
rsAdd.LockType = 3
rsAdd.Open strSQL, strCon

'Add a new record

rsAdd.Fields("Name")  = Request.Form("Name")
rsAdd.Fields("Msg")  = Request.Form("Msg")


'Reset server objects
Set rsAdd = Nothing


Let me remind you that this is the simplest shoutbox, which we used just for an example.
You can add javascript form check, option that with a help of cookie makes it possible to remember visitors name after a first written message, and more.

Are you a website owner?
Click here to register and submit your tutorials!

Browse by category

Most popular tutorials