PHP Solutions (First Edition): Corrections and Updates

NOTE: This page is no longer actively maintained. Its original purpose was to keep readers of the first edition of PHP Solutions up to date with new developments since the book's original publication in 2006. Factual errors and corrections were hosted on the friends of ED website, which closed down in 2011. I have found a copy of the foED errata page and added its contents here.

Corrections to the Second Edition are listed separately.

Installing Apache and PHP on Windows Vista

Before installing Apache and PHP on Windows Vista, turn off User Access Control (UAC). You can turn UAC on again after installation. If you attempt to install them with UAC enabled, Vista locates vital files in the wrong place.

To disable UAC, log into Vista as an administrator, and open Control Panel. Select Classic View, double-click the User Accounts icon, and then click "Turn User Account Control on or off". Deselect the Use User Account Control (UAC) checkbox, and click OK. Click Restart Now when prompted by Vista.

To re-enable UAC, follow the same procedure, but select the Use User Account Control (UAC) checkbox.

Windows PHP installer now offers full features

The release of PHP 5.2.0 is accompanied by a dramatically improved Windows installer. If you would prefer to automate the installation of PHP, see the full instructions for using the new installer in the Tutorials section of this site.

Enabling PHP on Mac OS X Leopard

When Mac OS X 10.5 was released (26 October 2007), the Mac PHP package created by Marc Liyanage that I recommended in the book was not compatible with Leopard. If a compatible version is still not available, follow the detailed instructions for setting up PHP in Leopard in the Tutorials section. Note: the version of PHP 5.2.4 in Leopard does NOT support PDO-MySQL.

PHP configuration changes since version 5.2

When you run phpinfo(), the location of php.ini is no longer displayed as Configuration File (php.ini) Path, but is in a new section called Loaded Configuration File immediately below.

The changes to allow_url_fopen originally planned for PHP 6 (see pages 180–181) were implemented in PHP 5.2. This means that allow_url_fopen no longer allows the inclusion of remote files. This change has no impact on the code in the book. However, if your hosting company still disables allow_url_fopen after upgrading to PHP 5.2 or later, you should ask it to review its security policy.

The distinction between allow_url_fopen and allow_url_include is subtle, but very important. Including a remote file directly in your scripts is a major security risk, so the default setting for allow_url_include is off. By making allow_url_include a separate configuration directive, the PHP team hopes to encourage administrators to turn on allow_url_fopen so that developers can access remote files such as RSS and XML feeds. Because allow_url_fopen on its own won't let you include such feeds directly in your pages, the responsibility lies on the individual developer to process the content of the feed to ensure that it doesn't contain any malicious script.

MySQL Windows Essentials

The separate version of the MySQL Community Server for 64-bit versions of Windows (mentioned on page 264) disappeared for some time, but now seems to be available again (thanks to Adriana for pointing out its reappearance).

PHP connector files no longer needed (Windows)

Please ignore the instructions on page 270 about downloading PHP connector files for MySQL. They are no longer needed, and have been removed from the MySQL site.

Changes to phpMyAdmin 3.0

The user interface for defining new tables in phpMyAdmin has changed in phpMyAdmin 3, which was released in late September 2008. See my blog entry for a list of the differences.

Factual Errors & Corrections

p.41

(Final paragraph) Since PHP 5.2.3, the version of php.ini read by your computer at startup is displayed as "Loaded Configuration File".

p.41

Insert the following between the first and second sentences of the final paragraph: "Since PHP 5.2.3, the location of php.ini is shown on the line immediately below as Loaded Configuration File."

p.66

In Table 3-1, the result shown for modulo division, although mathematically correct, would be 0 in a PHP script. This is because PHP converts numbers to integers when performing modulo division. Change $z to 3 and the result is correct.

p.96 - 102

PHP Solutions 4-3 and 4-4 pass the superglobal variable $_SERVER['SCRIPT_NAME'] as an argument to basename() to determine the name of the current page. Unfortunately, if your hosting company runs PHP as a
CGI on Apache, this outputs "php.cgi" instead of the name of the actual page. To get round this problem, use $_SERVER['SCRIPT_FILENAME'] instead of $_SERVER['SCRIPT_NAME'].

(Thanks to webinator for testing this fix.)

p.132

In step 4, the third line of code should read as follows:

if ($_POST && isset($missing) && !empty($missing)) {

This ensures that the first error message is displayed only if not all required fields have been filled in. It's possible that the user has filled in all fields, but the mail was not sent due to server error. (Thanks to Caroline Schnapp for pointing this out.)

p.142

Add the following at the foot of the page: "When adding extra form elements, don't forget to add their names to the $expected array. Otherwise they won't be processed."

p.180

Delete the following words at the end of the final sentence: "and notes changes planned in PHP 6."

p.181

The changes to allow_url_fopen and and allow_url_include were brought forward from PHP 6 to PHP 5.2. The change to safe_mode is still planned for PHP 6.

p.186

In the final paragraph of step 3, $users[0]['password'] should be $users[1]['password']. (Spotted by patfkellogg)

p.198

In step 4, buildImageList5 and buildImageList4 should be buildFileList5 and buildFileList4 respectively. (Thanks to FLA Rider)

p.222

In the switch statement, the word "created" has been wrongly appended to the value of $thumb_name in three places. In each case, the correct code should be $name followed by the appropriate filename extension, for example:

$thumb_name = $name.'_thb.jpg';

(Thanks to FLA Rider)

p.226

There's a step missing after step 3 in PHP Solution 8-3. Since $original now refers to the temporary file, you also need to change the line that assigns the value to $name. Replace basename($original) with basename($_FILES['image']['name']), so the complete line looks like this:

$name = preg_replace($imagetypes, '', basename($_FILES['image']['name']));

(Thanks to genji for spotting this omission.)

p.227

In the final paragraph, upload_test02.php should be upload_thumb02.php. (Thanks to FLA Rider)

p.324

An opening curly brace is missing at the end of line 4 of the code in step 2. It should read:
if (!@include('includes/connection.inc.php')) {
(Thanks to Pat Kellogg.)

p.334

In Step 2, the line that sets the value of $totalPix should be amended in the PDO code ONLY as follows:

$totalPix = $row;

This is because the PDO method fetchColumn() retrieves a single column, rather than the entire row. (Thanks to grillecloth for pointing out that the original code produced unexpected results with more than nine images listed in the database.)

p.405 - 406

NULL should be in quotes in the following line at the foot of page 405:
$image_id = NULL;
Amend the first paragraph at the top of page of page 406 to read as follows: "If $image_id contains no value or if it's not a number, its value is set tothe string 'NULL'. Inside the SQL query, this is treated as the keyword NULL because $image_id is not enclosed in quotes. Although this sounds counter-intuitive, the SQL query is built as a string. It's the use of quotes inside the query that determines how MySQL treats a value."

p.415

The lines of code :

"FROM column_name LEFT JOIN column_name ON matching_condition"
"FROM column_name LEFT JOIN column_name USING (column_name)"

should read:

"FROM table_name LEFT JOIN table_name ON matching_condition"
"FROM table_name LEFT JOIN table_name USING (column_name)"

(Thanks to Mark Anderson)

More about this book

PHP Solutions, Second Edition

Corrections to Second Edition

Other Books & Videos by David Powers

Introducing PHP

Up & Running with phpMyAdmin

Responsive Design with Bootstrap and Dreamweaver CC 2015

PHP Solutions, Third Edition

PHP for Web Designers

Beginning CSS3

Dreamweaver CS6: Learn by Video

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

PHP SolutionsBeginning CSS3Dreamweaver CS6: Learn by VideoDreamweaver CS5.5: Learn by VideoDreamweaver CS5.5 for MobileDreamweaver CS5 with PHP