Submitting
information
In order to use a database with
your web site, you must be able to connect to and interact with the database
from your web pages. In order to interact with the database, a user will
often use a web form to submit information to a web application, which will
process that information, reading and writing to the database as needed.
There are different ways in
which you can submit information from a web form and these are discussed
below.
GET and POST
When submitting a form on a web
site, two of the most common methods for submitting the form are GET and
POST. The method specified affects the way in which the information
specified in the form is transmitted to the web server. When information is
submitted from a form, it is submitted as name=value pairs, separated by an
ampersand (&) character. Spaces are replaced by the addition (+) symbol
Using a simple form as an
example, with just three fields, the information would be submitted as
follows:
name=Billy+Brown&age=27&location=glasgow
If GET is specified as the
method, then the browser will append the data to the actual URL of the
receiving page. Using the same example, the GET method would transfer the
information as follows:
GET
http://www.somewebsite.com/guestbook.asp?name=Billy+Brown&age=27&location=Glasgow
If POST is used as the method
instead, then the data would be transferred after the URL and some other
header information. The POST method would alert the web server to the fact
that information is to follow. Therefore the information would be
transferred now as:
POST
http://www.somewebsite.com/guestbook.asp
....[further header
information]
name=Billy+Brown&age=27&location=Glasgow
GET
is the default form action, but POST is probably the better method to use as
the information is hidden from the user and is therefore not as easily
accessible by the user.
Mailto
An alternative to using GET and
POST to submit your web form to a web application or ASP page is to use the
mailto action. Mailto will use the e-mail program of the user to create an
e-mail which should contain the information specified in the fields of the
web form. Using mailto is not totally reliable however and may just create a
blank e-mail addressed to the intended recipient, so it should only be used
with caution.
You should also realise that
this method does not allow the user to interact directly with a database as
the information is sent to an e-mail address and not a web application.
Web applications
There are various types of web
application that can be used to parse and process the information submitted
by a web form. Two of the most common are CGI applications and scripts, and
Active Server Pages (ASP). Whichever method you choose to use, to interact
with databases a connection will have to be established between the
application and the database, and this will be discussed in more detail
later on.
CGI applications
CGI stands for Common Gateway
Interface. When a form is submitted for a CGI application, a connection is
opened with the CGI program on the web server. The program can be written in
a variety of ways and languages, and the programmer can use and manipulate
the data in whatever way they desire. For example, the application could be
a .exe compiled application written using Borland Delphi. Once processing is
complete, a resulting page is sent back to the browser.
Active Server Pages
Active Server Pages work
differently from CGI applications because the code is stored in the same
text file that is used to display the web page. When the server realises
that it is dealing with an ASP file, it processes the ASP code before
sending the resulting page to the browser. Therefore, ASP is independent of
browser implementation, unlike JavaScript, which is processed by the
browser. |