Database Reference
In-Depth Information
change the definition of the ENUM column. In each case, you change the set of items in
a form element by updating the database, not by modifying the script; the script adapts
to the change without additional programming.
The first part of this chapter covers the following topics relating to web input processing:
Generating forms and form elements
One way to use database content for form construction is to select a list of items
from a table and create the options in a list element. But metadata can be used as
well. There is a natural correspondence between ENUM columns and single-pick form
elements like radio button sets or pop-up menus. In both cases, only one from a set
of possible values may be chosen. There is a similar correspondence between SET
columns and multiple-pick elements like checkbox groups; any or all of the possible
values may be chosen.
Initializing forms using database contents
In addition to using the database to create structural elements of forms, you can
also use it to initialize their values. For example, to enable a user to modify an
existing record, retrieve it from the database and load its values into the corre‐
sponding form fields before sending the form to the user for editing.
Processing input gathered over the Web
This includes input not only from form fields, but also the contents of uploaded
files, or parameters in URLs. Regardless of how you obtain the information, you
face a common set of issues in dealing with it: extracting and decoding the infor‐
mation, performing constraint or validity checking on it, and re-encoding the in‐
formation for SQL statement construction to avoid generating malformed state‐
ments or storing information inaccurately.
The second part of the chapter illustrates how to apply the techniques developed in the
first part. These include applications that show how to use MySQL to present a web-
based search interface, create paged displays that contain next-page and previous-page
links, implement per-page hit counting and logging, and perform Apache logging to a
database.
Scripts to create tables used in this chapter are located in the tables directory of the
recipes distribution. Scripts for the examples are located under the directories named
for the web servers used to run them. For Perl, Ruby, PHP, and Python examples, look
under the apache directory. Utility routines used by the example scripts are found in
files located in the lib directory. (For information on configuring Apache so that scripts
run by it can find their library files, see Recipe 18.2 .) For Java (JSP) examples, look under
the tomcat directory; you should already have installed these in the process of setting
up the mcb application context (see Recipe 18.3 ).
If a particular section has no example for a language in which you're interested, check
the recipes distribution for implementations not shown here.
Search WWH ::




Custom Search