Specifications

FIGURE 10.2
The results of searching the database for books about Java are presented in a Web page using the
results.php script.
The Basic Steps in Querying a Database
from the Web
In any script used to access a database from the Web, you will follow some basic steps:
1. Check and filter data coming from the user.
2. Set up a connection to the appropriate database.
3. Query the database.
4. Retrieve the results.
5. Present the results back to the user.
These are the steps we have followed in the script results.php, and we will go through each of
them in turn.
Checking and Filtering Input Data
We begin our script by stripping any whitespace that the user might have inadvertently entered
at the beginning or end of his search term. We do this by applying the function
trim() to
$searchterm.
trim($searchterm);
Using MySQL
P
ART II
232
13 7842 CH10 3/6/01 3:36 PM Page 232