Tutorial PHP : Web Pages that Manipulate Database Records
Sample of the pdf document :
Inserting and Updating Data
In this tutorial, you’ll continue working on the National Exasperator’s online store. You’ll work on two
administrative pages that allow employees of the National Exasperator to add new products to the
database, and to edit products already in the database.
This tutorial assumes you’ve already completed parts I and II of the PHP Tutorial. If not, start with
phpTutorial1.pdf, follow the instructions for preparing the application server, database, and Dreamweaver
for this project. Then turn to phpTutorial2.pdf and build the product catalog pages.
Adding an Insert Product Page
Start by opening a page that’s already been created.
1. Open the file named add_product.php in the admin folder of the local site you defined in Chapter 20.
Pages for adding and editing the online store’s products shouldn’t be accessible to the public; you
wouldn’t want just anyone adding products—“The Electric Whoopee Cushion, by Mr. Hacker,” for
example—to the store. Accordingly, these pages are kept in a folder reserved for administrators of the
Web site. (In the next chapter, you’ll learn how to password protect these pages.)
One piece of information required for each new product is an ID number for the vendor who
manufactures the product. The database for these products actually contains several tables: Products,
Vendors, and Category. Information about each vendor (name and contact info) is in the Vendors table,
while information on each product (price, description, and so on) is in the Products table. A third table
contains a list of product categories, which you used in the last tutorial to create the category
navigation bar.
To keep the Vendors and Products tables connected, so that you know which vendor manufactures
which product, the Products table includes a field containing the vendor’s ID number. Whenever you
add an item to the Products table, then, you also need to insert the vendor’s ID number.
To make the process of selecting a vendor easier, you should add a pop-up menu that lists all of the
vendors in the database. To make this kind of dynamic menu, start by creating a recordset.
2. Choose Insert→Application Objects→Recordset.
Or use any of the methods described on page 706 of the printed book to add a new recordset; for
example, clicking the + button in either the Bindings or Server Behaviors panels and choosing
Recordset (Query). The Recordset window opens. Make sure that the simple recordset options show up
(see Figure PHP Tutorial 3-1). Next, you’ll define the properties of this recordset.
3. Type rsVendors in the Name box. Select connNationalEx from the Connection menu. Select “vendors”
from the Table menu.
These three steps set up the name, database, and table required for the recordset. For a recap of creating
recordsets, turn to page 706.
4. Click the Selected radio button; select vendorID and vendorName from the Columns list.
You can do this by holding down the Ctrl (Option) key while clicking the name of each column.
Finally, pick an order for sorting the list of vendors.
5. Choose vendorName from the Sort menu. Make sure Ascending is selected in the Order menu.......
Click here for Download PDF / FREE
0 commentaires: