Database Reference
In-Depth Information
Figure 11-34
Modifications to the VrG
index.html Home Page
Similarly, SQL Server uses the sqlsrv_connect function (using the Microsoft PHP driver
described in footnote 8), and Oracle Database uses the oci_connect function.
PHP 5.3.x and 5.4.x also support object-oriented programming and a new data abstraction
layer called PHP Data Objects (PDO) that provides a common syntax for accessing DBMS
products. There is a lot of power in PHP, and we will barely scratch the surface here.
However, before proceeding with our examples, we need to add some links to our VRG
homepage. The necessary code is shown in Figure 11-34. If you are working through these
examples (and you should be), be sure to make these changes.
Example 1: Updating a Table
The previous example of a PHP Web page just read data. This next example shows how to
update table data by adding a row to a table with PHP. Figure 11-35 shows a data entry form that
will capture artist name and nationality and create a new row. This form has three data entry
fields: the First Name and Last Name fields are text boxes where the user types in the artist's
name, and the Nationality field has been implemented as a drop-down list to control the pos-
sible values and to make sure they are spelled correctly. When the user click the Add New Artist
button, the artist is added to the database; and if the results are successful, the acknowledgment
Web page in Figure 11-36 is displayed. The Display the ARTIST Table (LastName, FirstName,
Nationality) link will invoke the ReadArtist.php page, which will display the ARTIST table with
the new row, as shown in Figure 11-37. We have tested these pages by adding the American artist
Guy Anderson (born 1906, deceased 1998), who is a member of the Northwest School.
This processing necessitates two PHP pages. The first, shown in Figure 11-38, is the data
entry form with three fields: artist last name, artist first name, and artist nationality.
It also contains the form tag:
<form action="InsertNewArtist.php" method="POST">
This tag defines a form section on the page, and the section will be set up to obtain data
entry values. This form has only one data entry value: the table name. The POST method
refers to a process that causes the data in the form (here the last name, the first name, and
the selected nationality) to be delivered to the PHP server so they can be used in an array
variable named $_POST. Note that $_POST is an array and thus can have multiple values.
 
Search WWH ::




Custom Search