Web Design

(Nancy Kaufman) #1

284


Process Form Data .................................................


4 In your editor, open a new
or existing document.
5 Within the body of the
document, type <?php.
6 Type echo “?:”;,
replacing? with the label
from the first form field.
7 Type echo $_POST[‘?’],
replacing? with the first
form field name.
8 Type echo “<br />”;.
9 Repeat Steps 6 to 8 for each
additional form field you
want to display.

1 In your editor, open an HTML
document that contains an
existing form.

Note: Be sure that the document
is saved in the Web server’s root
folder.


2 Note the names of each of
the fields in the form.

3 Note the filename specified in
the form’s action attribute.

Process Form Data


W


ith PHP, you can accept data from an online form and have your site respond according to the
data your use entered. Form data may be accessed in a PHP page by referencing a super-global,
which is a special type of built-in variable in the language. The $_POST super-global contains
a reference to any form field submitted to the page. For example, a field in HTML with a name
attribute set to firstName can be accessed by writing $_POST[‘firstName’]. Note that the
field names are case-sensitive, so they must match your HTML exactly.

1


4


5


7


6


3


2


8


9

Free download pdf