PHP Solutions (Second Edition): Corrections

This page lists known errors in the Second Edition of PHP Solutions: Dynamic Web Design Made Easy, published by friends of ED in November 2010. Updates and Corrections to the First Edition are listed separately.

Download files: The friends of ED site has been merged with the main Apress site. The example files can now be downloaded from the book's page on the merged site.

Page 113: Amend the code in step 6 to add a new line in the conditional statement that adds required fields to the $missing array if empty like this:

if (empty($temp) && in_array($key, $required)) { $missing[] = $key; ${$key} = ''; } elseif . . .

This creates a variable with the name of the missing field and sets its value to an empty string. Making this change prevents a warning about an "undefined variable" being displayed in PHP Solution 5-3 if no value is entered in a required field.

Pages 136–137: PHP Solution 5-9 describes how to handle check box groups. If you want to deal with a single check box, you need to make several changes.

First of all, the name attribute for a single check box must not end in a pair of square brackets. For example, a check box that asks users to accept terms and conditions might use name="terms".

You also need to create an element in the $errors array if the check box hasn't been selected. Do this at the same time as testing for the existence of the $_POST element in step 2 like this:

if (!isset($_POST['terms'])) { $_POST['terms'] = ''; $errors['terms'] = true; }

Finally, because you're not using an array, you can't use in_array() in the sticky input field code. Change the code in step 1 like this:

<input type="checkbox" name="terms" value="accepted" id="terms" <?php if ($_POST && isset($_POST['terms'])) { echo 'checked'; } ?>> <label for="terms">I accept the terms</label>

Page 211: A curly brace is missing after the final call to header("Location: $error") at the end of the code listing in step 2. The correct code looks like this:

} else { header("Location: $error"); } }

Pages 251–258: The file-based authentication example in PHP Solutions 9-3 to 9-5 fails if you rely on the download files. There are two problems:

First, the code on line 6 of login_02.php should be the same as in step 2 on page 252, namely:

$password = $_POST['pwd'];

The other problem concerns filetest_02.txt, which is in the ch07 folder. If you use the download version, the login fails for "david" and "codeslave", but not for "chris" and "bigboss". After extensive testing, I discovered this is because the file was saved in Windows Notepad using UTF-8 encoding. Apparently, Windows inserts an invisible character at the beginning of the file to indicate the encoding.

There are two ways to fix this problem. The simple way is to insert a blank line at the start of the file. This leaves the invisible character on the first line. Subsequent lines contain only text. Alternatively, you can remove the invisible character by changing the file's encoding as follows:

Page 307: The first three lines of code at the top of the page should be rewritten like this:

if ($connectionType == 'mysqli') { $conn = new mysqli($host, $user, $pwd, $db); if ($conn->connect_error) { die('Cannot open database'); } return $conn; } else {

However, it's important to note that the connect_error property does not work correctly prior to PHP 5.2.9 or 5.3.0. If your server uses an older version of PHP, replace the third line in the revised code block with the following:

if (mysqli_connect_error()) {

Page 356: If your copy of the download files doesn't contain blog.sql, you can get a copy here.

Pages 375–376: There's a mistake in blog_delete_mysqli.php in the download files. Line 20 should look like this:

$OK = $stmt->execute();

This is necessary to reset the value of $OK to true. Otherwise, you see a warning about $error being an undefined variable on line 46 when the page first loads.

More about this book

Book's Main Description

Updates and Corrections to First Edition

Other Books & Videos by David Powers

PHP for Web Designers

Beginning CSS3

Dreamweaver CS6: Learn by Video

Introducing PHP

HTML5, CSS3, and jQuery with Adobe Dreamweaver CS5.5: Learn by Video

Adobe Dreamweaver CS5.5 Studio Techniques: Designing and Developing for Mobile with jQuery, HTML5, and CSS3

Adobe Dreamweaver CS5 with PHP: Training from the Source

PHP Object-Oriented Solutions

Buy from one of these online stores

Free 7-day trial

Books & Videos by David Powers

Beginning CSS3Dreamweaver CS6: Learn by VideoDreamweaver CS5.5: Learn by VideoDreamweaver CS5.5 for MobilePHP SolutionsDreamweaver CS5 with PHP