It should be set to this already if you didn't change it after downloading it from the book site. 3) After that, place form.html, the css folder, and this file (show-data.php) on a web server that has PHP installed. For example, if you have an account with a web host, you could upload the files to your server (see Chapter 21). The vast majority of web host accounts have PHP pre-installed, so you shouldn't have to do anything special beyond uploading the files. But, if the form doesn't work after you upload the files, your web host or their site's help pages may be of assistance. You may also test the form on your own computer if you have PHP and a web server such as Apache installed and running. OS X (Macs) has these installed by default. More information for enabling these is available at, although some of the process is a little technical. You may find it easier to download one of the following packages that install Apache, PHP, MySQL and more on your computer, and provide an interface for you to turn them on and off easily. - OS X only: MAMP ( - Windows only: WampServer ( - Linux, OS, or Windows: XAMPP ( Search online for more information about using one of these packages. */ ?>

Information Submitted with Form

This script needs to be run on a web server to work. Open this file in your text editor and read the comment that begins with "TO TEST THIS SCRIPT" for additional information.

This is a very simple PHP script that displays each bit of information that was sent when form.html was submitted (by using the "Create Acount" button). The left column of the table below lists the name attribute of each form field as defined in form.html. The right column shows each field's value as sent with the submitted form.

In a more useful script, you might store this information in a MySQL database, or send it to your email address.

Important Note: The sample PHP code in this file is meant for demonstration purposes only and is simple by design, and as a result, it doesn't include the security checks that a bulletproof script would include. Given that, I don't recommend you use it as-is on your site. If you do intend to use a script like this, I recommend consulting PHP books and other resources to learn how to check submitted form values for malicious data before you write the values to the screen or to a database, or send them via email, as well as any other methods that will make it secure.

The script also does not check each to see if the user provided information for each form field.

"; } else { /* Data was submitted, so show it in the page. */ foreach ($_POST as $key => $value) { /* Cleans up quoted values. See: */ if ($key != 'email_signup') { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } } /* Check the form field and print its value in a table row */ if ($key == 'email_signup') { // True if one of the Email checkboxes at end if (is_array($_POST['email_signup'])) { // True if a checkbox checked // Print the name of the checkbox form field and the value foreach ($_POST['email_signup'] as $value) { print "\n"; } } else { print "\n"; } } else { // Print row and info for form fields except the Email checkboxes print "\n"; } } } /* Display the file upload picture name */ if(isset($_FILES['picture'])) { /* This basic script presents the name of the uploaded file only. To check the file size, file type (like JPG, GIF, or PNG), and actually upload a file to a folder, see the video tutorial at The code explained in the video is also available for download from that URL. That page also includes links to a series of videos about using PHP. */ $picture_name = $_FILES['picture']['name']; print "\n"; } ?>
Field Name Value(s)

No data was submitted.

$value"; print "on"; print "