Database Reference
In-Depth Information
CHAPTER 20
Processing Web Input with MySQL
20.0. Introduction
The previous chapter describes how to retrieve information from MySQL and display
it in web pages using HTML constructs such as tables or hyperlinks. That's a use of
MySQL to send information in one direction (from web server to user). This chapter
considers the use of MySQL in the other direction: web-based database programming
to collect information sent from user to web server, such as the contents of a submitted
form. For example, you might store the information from a survey form for later use,
or use keywords from a lookup form as the basis for a query to search the database for
information the user wants.
MySQL comes into these activities as the repository for storing information or as the
source from which search results are drawn. But before you can process input from a
form, you must create the form and send it to the user. MySQL helps with this, too,
because it's often possible to use information from your database to generate form ele‐
ments such as radio buttons, checkboxes, pop-up menus, or scrolling lists:
• Select a set of items from a table that lists countries, states, or provinces and convert
them into a pop-up menu in a form that collects address information.
• Use the list of legal values for an ENUM column that contains permitted colors or
sizes to generate a set of radio buttons.
• Use lists of available colors, sizes, or styles stored in an inventory database to con‐
struct fields for a clothing ordering form.
Using database content to generate form elements lessens the amount of explicit knowl‐
edge your programs must have about table structure and content, and enables them to
determine what they need automatically. A script that uses database content to generate
form elements also adaptively handles changes to the database. To add a new country,
create a new row in the table that stores the list of countries. To add a new salutation,
 
Search WWH ::




Custom Search