Database Reference
In-Depth Information
An alternative method is GET, but POST can carry more data, and this distinction is not
too important to us here. The second parameter of the form tag is action, which is set to
InsertNewArtist.php. This parameter tells the Web server that when it receives the response
from this form it should store the data values in the $_POST array and pass control to the
InsertNewArtist.php page.
The rest of the page is standard HTML, with the addition of the . . . structure for creating
a drop-down list in the form. Note that the variable name for the selected value is Nationality.
When the user clicks the Add New Artist button, these data are to be processed by the
InsertNewArtist.php page. Figure 11-39 shows the InsertNewArtist.php, the page that will be
invoked when the response is received from the form. Note that the variable values for the
INSERT statement are obtained from the $_POST[] array. First, we create short variable names
for the $_POST version of the name, and then we use these short variable names to create the
SQL INSERT statement. Thus:
// Create short variable names
$LastName = $_POST["LastName"];
$FirstName = $_POST["FirstName"];
$Nationality = $_POST["Nationality"];
// Create SQL statement
$SQL = "INSERT INTO ARTIST(LastName, FirstName, Nationality) ";
$SQL .= "VALUES('$LastName', '$FirstName', '$Nationality')";
Note the use of the PHP concatenation operator (.=) (a combination of a period and an
equals sign) to combine the two sections of the SQL INSERT statement. As another example,
to create a variable named $AllOfUs with the value me, myself, and I, we would use:
$AllOfUs = "me, ";
$AllOfUs .= "myself, ";
$AllOfUs .= "and I";
Most of the code is self-explanatory, but make sure you understand how it works.
Figure 11-39
the HtML and PHP Code
for InsertNewartist.php
 
Search WWH ::




Custom Search