Home         Back

 

 

 

Saivaneri Web Tutor

CHAPTER 13

LTNS, isn’t it?. But we have got to know more in the meantime. This chapter explains How To Host FREE DATABASE ENABLED WEBSITE. Normally you would have to pay at least Rs.1000 per annum to add database support to a Linux server. For windows too. So the total cost of owning a website gets higher than ever. There are free solutions to this in the form of www.brinkster.com for Access based databases, or free FLAT FILE data basing solutions for LINUX servers. 

We will see how to host on brinkster an access database. It’s really fast and simple. No ads, no fee, just pull the code below and eNjoY!. 

The ASP (Active Server Pages) code to call a MS Access GUEST BOOK DATABASE:-

To test run the ASP scripts, you must have PWS (personal web server) for windows 98 loaded on your system. On a Windows XP machine IIS (Internet Information Server) is already installed on your system. You can start your local web server by typing your  

http://machine name (in my case it is http://pasco)

http://localhost

http://127.0.0.1 

Remember these URLs are running on LOCAL MACHINE only, so cannot by accessed on the WWW. 

All local machine servers have a folder called C:\Inetpub\wwwroot. This is the folder where your htm. Html or asp pages are published. You can publish to your local server from Macromedia Dream weaver or MS FrontPage. Or you can directly go to the folder wwwroot and create a subfolder for your web site, and then do all these practice exercise as given in this chapter. You can name a folder called Tutorial so that our examples will run from there 

To run the following code, copy the following ASP files and Database.mdb file to the C:\Inetpub\wwwroot\Tutorial folder. You can call the asp file now by typing http://localhost/database1.asp 

Creating a Guest Book using a Database

This lesson requires that you have Microsoft Access installed on your system

Guest books allow your Web site visitors to leave behind information, such as their names, e-mail addresses, and comments. In this lesson, you perform the following tasks after creating an Access database:

·                         Example 1   Create an ASP page to connect to the database using only the ADO Connection object.  

Create an Access Database

Create an Access database called GuestBook.mdb, and save it in x:\Inetpub\Wwwroot\Tutorial. Create a table in the database called GuestBook. Use the Create Table Using Design View option in Access to add the following fields and properties:

Field Name

Data Type

Field General Properties

FID

AutoNumber

Field Size=Long Integer,
New Values=Increment,
Indexed=Yes(No Duplicates)

FTB1

Text

Field Size=255,
Required=No,
Allow Zero Length=Yes,
Indexed=No

FTB2

Text

Field Size=255,
Required=No,
Allow Zero Length=Yes,
Indexed=No

FTB3

Text

Field Size=255,
Required=No,
Allow Zero Length=Yes,
Indexed=No

FTB4

Text

Field Size=255,
Required=No,
Allow Zero Length=Yes,
Indexed=No

FMB1

Memo

Required=No,
Allow Zero Length=Yes

Create an ASP Page to Add Data to Your Access Database

Now that you have created a database, you can build an ASP page to connect to your database and read incoming data using Microsoft ActiveX® Data Objects (ADO). ADO is a collection of objects with methods and properties that can manipulate data in almost any type of database. (If you plan to use databases frequently, you should purchase a programmer's reference book for ADO. Only the most basic ADO code is illustrated in the following examples, enough to open, read in, and write to a database.) 

The next two examples produce the same results; however, the first example uses only the Connection object, and the second example gives part of the job to the Command object, which is much more powerful. Compare both examples to see how the objects become connected together. After you are comfortable with the objects, use an ADO programmer's reference to experiment with more methods and properties.

To see an example of an ADO error in your ASP page, try browsing to the page after renaming your database, after entering a typing mistake in the connection string, or after making the database Read Only.

 

Example 1: Using Only the ADO Connection Object – The ASP SCRIPT

Copy and paste the following code in your text editor, and save the file as GuestBook1.asp in the x:\Inetpub\Wwwroot\Tutorial directory. View the example with your browser by typing http://localhost/Tutorial/GuestBook1.asp in the address bar.

  <%@ Language=VBScript %>

  <html>
  <head>
  <title>Guest Book Using Connection Object Only</title>
  </head>
  <body>
  <font face="MS Gothic">
  <h2>Guest Book Using Connection Object Only</h2>

  <%
   If Not Request.QueryString("Message") = "True" Then
     'No information has been input yet, so provide the form.
  %>
     <p>
     <FORM NAME="GuestBook1" METHOD="GET" ACTION="guestbook1.asp">
     <table>
       <tr>
       <td><font face="MS Gothic">From:</td><td><INPUT TYPE="TEXT" NAME="From"></td>
       </tr><tr>
       <td><font face="MS Gothic">E-mail Address:</td><td><INPUT TYPE="TEXT" NAME="EmailAdd"></td>
       </tr><tr>
       <td><font face="MS Gothic">CC:</td><td><INPUT TYPE="TEXT" NAME="CC"></td>
       </tr><tr>
       <td><font face="MS Gothic">Subject:</td><td><INPUT TYPE="TEXT" NAME="Subject"></td>
       </tr>
     </table>
     Message:<br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>
     </p>

     <p>
     <INPUT TYPE="HIDDEN" NAME="Message" VALUE="True">
     <INPUT TYPE="SUBMIT" VALUE="Submit Information">
     </FORM>
     </p>
  <%
   Else
     'The HIDDEN button above sets the Message variable to True.
     'We know now that form data has been entered.

     'Get the data from the form. We will be inserting it into the database.
     'Access doesn't like some characters, such as single-quotes, so encode the
     ' data using the HTMLEncode method of the ASP Server object.
     dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
     strTB1 = Server.HTMLEncode(Request.QueryString("From"))
     strTB2 = Server.HTMLEncode(Request.QueryString("EMailAdd"))
     strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
     strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
     strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))

     'This is a connection string. ADO uses it to connect to a database through the Access driver.
     'It needs the provider name of the Access driver and the name of the Access database.
     'Connection strings are slightly different, depending on the provider being used,
     ' but they all use semicolons to separate variables.
     'If this line causes and error, search in your registry for
     ' Microsoft.JET to see if 4.0 is your version.
     strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\InetPub\Wwwroot\Tutorial\guestbook.mdb;"

     'This creates an instance of an ADO Connection object.
     'There are 4 other ADO objects available to you, each with different methods and
     'properties that allow you to do almost anything with database data.
     Set objConn = server.createobject("ADODB.Connection")

     'The Open method of the Connection object uses the connection string to
     ' create a connection to the database.
     objConn.Open strProvider

     'Define the query.
     'There are many types of queries, allowing you to add, remove, or get data.
     'This query will add your data into the database, using the INSERT INTO key words.
     'Here, GuestBook is the name of the table.
     'You need single-quotes around strings here.
     strCommand = "INSERT INTO GuestBook (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
     strCommand = strCommand & strTB1 & "','" & strTB2 & "','" & strTB3 & "','" & strTB4 & "','" & strMB1
     strCommand = strCommand & "')"

     'Execute the query to add the data to the database.
     objConn.Execute strCommand

     Response.Write("Thank you! Your data has been added.")

     End If
  %>

  </font>
  </body>
  </html>

see to that your database PATH is correctly mentioned in the script.

Now how to upload this file to www.brinkster.com ?

Go get a FREE 20 MB webspace in www.brinkster.com the URL to your site is normally http://www26.brinkster.com/yoursitename/

While registering be careful because the username and site name is to be same.

My site name is http://www26.brinkster.com/vkplexa/

Check with my site name by going to these URLS

http://www26.brinkster.com/vkplexa/brinkguestbook.asp

http://www26.brinkster.com/vkplexa/brinksai_gals.asp

after registering an account with brinkster, go to file manager, upload your ASP files to the root folder there, and upload database files to /db folder.

The working of ASP on the brinkster is slightly different so be careful to amend the ASP file on your local machine before uploading the file to the brinkster server.

 

AMENDMENTS TO BE DONE ON DATABASE.ASP FILE BEFORE UPLOAD TO BRINKSTER (RED COLORED TEXT IS THE ONLY AMENDMENTSALL OTHER TEXT ARE SAME)

NAME THIS FILE AS brinkguestbook.asp THEN UPLOAD TO YOUR SITE.

<%@ Language=VBScript %>

  <html>

  <head>

  <title>Guest Book Using Connection Object Only</title>

  </head>

  <body>

  <font face="MS Gothic">

  <h2>Guest Book Using Connection Object Only</h2>

 

  <%

   If Not Request.QueryString("Message") = "True" Then

     'No information has been input yet, so provide the form.

  %>

     <p>

     <FORM NAME="GuestBook1" METHOD="GET" ACTION="brinkguestbook.asp">

     <table>

       <tr>

       <td><font face="MS Gothic">From:</td><td><INPUT TYPE="TEXT" NAME="From"></td>

       </tr><tr>

       <td><font face="MS Gothic">E-mail Address:</td><td><INPUT TYPE="TEXT" NAME="EmailAdd"></td>

       </tr><tr>

       <td><font face="MS Gothic">CC:</td><td><INPUT TYPE="TEXT" NAME="CC"></td>

       </tr><tr>

       <td><font face="MS Gothic">Subject:</td><td><INPUT TYPE="TEXT" NAME="Subject"></td>

       </tr>

     </table>

     Message:<br><TEXTAREA NAME="Memo" ROWS=6 COLS=70></TEXTAREA>

     </p>

 

     <p>

     <INPUT TYPE="HIDDEN" NAME="Message" VALUE="True">

     <INPUT TYPE="SUBMIT" VALUE="Submit Information">

     </FORM>

     </p>

  <%

   Else

    

     dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand

     strTB1 = Server.HTMLEncode(Request.QueryString("From"))

     strTB2 = Server.HTMLEncode(Request.QueryString("EMailAdd"))

     strTB3 = Server.HTMLEncode(Request.QueryString("CC"))

     strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))

     strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))

 

'use your site name

 

Set oConn = Server.CreateObject("ADODB.Connection")

sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

              "Data Source=" & Server.MapPath("\vkplexa\db\guestbook.mdb") & ";" & _

              "Persist Security Info=False"

oConn.Open(sConnection)    

     strCommand = "INSERT INTO GuestBook (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"

     strCommand = strCommand & strTB1 & "','" & strTB2 & "','" & strTB3 & "','" & strTB4 & "','" & strMB1

     strCommand = strCommand & "')"          

            oConn.Execute strCommand

            oConn.Close 

     Response.Write("Thank you! Your data has been added.")

      End If

  %>  

  </font>

  </body>

  </html>

PRACTISE:-

DO THIS CHAPTER AT YOUR HOME AND ON THE SERVER. CALL ME TO VISIT IT. NEXT CHAPTER WE WILL SEE HOW TO SEARCH, VIEW, DELETE THE RECORDS IN THE DATABASE.

 

PREVIOUS CHAPTER                 NEXT CHAPTER

FOR FULL CHAPTER PLEASE CLICK HERE