Errata

Learning PHP & MySQL

Errata for Learning PHP & MySQL, Second Edition

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page 8
Ex 1-1

Code comment incorrectly refers to "user_name" when it should refer to "comment"

Anonymous   
Printed
Page 10
5th paragraph

The line ending "...where it was referenced as user_admin.css" is incorrect.
The name of the style sheet used in the previous example was example.css

Change the line on page 10 to read:
Although we included the CSS in the file in this example, it could come from a separate file as it did in Example 1-1, where it was referenced as example.css.

Anonymous   
Printed
Page 11
3rd Paragraph

It reads:
(Instead of <b>bold<i>italic</i></b>, you should close the code like this: </b></i>.)

This is contradicted by the last sentence:
So, if you open a bold and then italic, you should close the italic before you close the bold.

So the correct manner would be: <b>bold<i>italic</i></b>

Page 11 should read:
It?s also good practice (and it?s required by XHTML) that your tags nest cleanly to produce elements with clear boundaries. Always use end tags when you reach the end of an element, and avoid having pairs of tags that overlap. (Instead of <b>bold<i>italic</b></i>, you should close the code like this: </i></b>.) In other words, you should open and close items at the same level. So if you open a bold and then italic, you should close the italic before you close the bold.

Anonymous   
Printed
Page 23
Please modify step 8

Figure 2-14 shows the ?Chose Items to Install? dialog. If you changed the base install directory, you may also need to change it here. If you?re installing PHP 5.2.6 or later, expand the extensions section and mark MySQL for installation. You may also install the MySQLi extension, which supports the latest MySQL features. Click Next.

Anonymous   
Printed
Page 25
Section entitled Enabling PHP on Mac OS X

I just wanted to note that with the release of OS X 10.5 (Leopard), that the location of httpd.conf has
changed and thus enabling PHP on 10.5 systems will not work with the directions as provided. For that
reason alone, I'm marking this as a serious technical mistake, even though it's still accurate for 10.4
and earlier systems.

The new location with 10.5 is in /etc/apache2/httpd.conf.

Add a note to page 25 just after step 2 (Type: sudo vi /etc/httpd/httpd.conf) that says:

Note: For Mac OS X Leopard the httpd.conf file is in /etc/apache2, so type: sudo vi /etc/apache2/httpd.conf

Anonymous   
Printed
Page 32
Installing MySQL Connector section

Although this is the latest edition (2007), the web address given http://dev.mysql.com/downloads/connector/php/ does not exist.

The page now seems to be http://dev.mysql.com/downloads/connector/php-mysqlnd/

PHP5 5.2.6 or later supports MySQL by using either the MySQL or MySQLi extensions. These are part of the PHP5 installer and are installed by expanding the Extensions node of the PHP installer shown in Figure 2-14. You way use either MySQL or MySQLi. You will need to manually add a line to the php.ini file such as:
extension=php_mysql.dll
or
extension=php_mysqli.dll
Also the file libmysql.dll must be copied from C:Program FilesPHP to C:WINDOWSsystem32.

Change this text:
The Connector/PHP download provides two .dll files for PHP that are required to use MySQL:
To:
The Connector/PHP download provides two .dll files for PHP that are required to use MySQL. If PHP 5.2.6 or later was installed with either the MySQL or MySQLi extension in Step 8 of the PHP installation skip to step 5:

Anonymous   
Printed
Page 33
After Step 6 on page 33 add this note

Note: If you selected to install MySQLi then use extension=php_mysqli.dll instead of extension=php_mysql.php.

Modify a sentence of Step 8 on page 33 from:
You should now see a section with the heading MySQL in the middle of the page.
To:
You should now see a section with the heading of MySQL or MySQLi in the middle of the page.

Anonymous   
Printed
Page 36
1st paragraph

The following sentence is incorrectly referring to "FTP Voyager" available from http://www.ftpvoyager.com/ :

"Graphical FTP clients make using FTP much easier, FTP Voyager, available from http://sourceforge.net/
filezilla/, is one FTP client you can use to upload files to your ISP."

I found this information on their download page:

"This copy of FTP Voyager will no longer function after the 30-day trial period has expired. In order to
continue using FTP Voyager after the trial period, you will need to purchase a Registration ID which
will make the program fully functional again."

The name of the open source FTP client at the URL listed on page 36 is "FileZilla".

Figure 2-31 on page 37 and Figure 2-32 on page 38 refer to FTP Voyager also and will need to be changed
to refer to screen from FileZilla.

Change the text to read:
FTP Voyager, available for a 30-day free trial from http://ftpvoyager.com, is one FTP client you can use to upload files to your ISP. Filezilla can also be used and is available for free from http://sourceforge.net/projects/filezilla/. Your initial login screen looks similar to Figure 2-31. Fetch is a good FTP program for Mac.

Anonymous   
Printed
Page 52

For the sake of clarity change the first bullet on page 52 to read:

Escape quotes within the string with a backslash. To escape a quote, just place a backslash directly before the quotation mark; i.e., ".
Also the text after example 3-16:
Example 3-16 escapes quotations by placing a backslash in front of each one ("). The backslash tells PHP that you want the quotation to be used within the string and not as the end of the echo?s string.

Anonymous   
Printed
Page 53
Last paragraph from the bottom.

Second sentence, $!result should be !$result

"If $result is true, then $!result is false, and vice versa."
...should read:
"If $result is true, then !$result is false, and vice versa."

Anonymous   
Printed
Page 60
5th line of Example 3-25

echo "Value afterwords: ".$test;
should be
echo "Value afterwards: ".$test;

Please change the text just after Example 3-25 (page 60) to:
<?php
$test=1;
echo "Preincrement: ".(++$test);
echo "<BR>";
echo "Value afterwards: ".$test;
echo "<BR>";
$test=1;
echo "Postincrement: ".($test++);
echo "<BR>";
echo "Value afterwards: ".$test;
?>
This produces the following:
Preincrement: 2
Value afterwards: 2
Postincrement: 1
Value afterwards: 2

Anonymous   
Printed
Page 65
First line after paragraph heading "Number of operands"

Different operands take different numbers of operands.

should be:

Different operators take different numbers of operands.

Anonymous   
Printed
Page 69
1st

5+3-2=8

The arithmetic is wrong, it should add up to 6.

Anonymous   
Printed
Page 72

The second bullet on page 72 should read:

? : (shorthand for an if statement)

Anonymous   
Printed
Page 74
directly above Ex 4-8 replace

{expression} ? return_when_expression_true : return_when_expression_false;
with:
(expression) ? return_when_expression_true : return_when_expression_false;

Anonymous   
Printed
Page 82
about the middle of the page

..."Of course, there may be times when you don?t want to just skip"..

should read as:

..."Of course, there may be times when you want to just skip"..

Anonymous   
Printed
Page 90

currently reads:

$str{0} = strtoupper($str{0}); //$str{0] accesses the first character in the string

Should read:
$str{0} = strtoupper($str{0}); //$str{0} accesses the first character in the string

Anonymous   
Printed
Page 91
Example 5-6

There are one to many "{" in Example 5-6 Deleting the first or second "{" corrects the code.

The code for Example 5-6 should be:
Example: Modifying capitalize() to take a reference parameter
<?php
function capitalize( &$str, $each=TRUE )
{ // First, convert all characters to lowercase
$str = strtolower($str);
if ($each === true) {
$str = ucwords($str);
} else {
$str{0} = strtoupper($str{0});
}
}
$str = "hEllo WoRld!";
capitalize( $str );
echo $str;
?>

Anonymous   
Printed
Page 104
Example 5-20

No closing ?> on the example

Also, the output does NOT match the description. It prints "the cat was hypnotized" twice, so it seems that $hypnotic_cat->hypnotize() DOES something, not as described in the comments and intro to the example. PHP 5.2.5
After this line on page 104:
$hypnotic_cat->hypnotize();
Please add the next line:
?>
It should read:
$hypnotic_cat->hypnotize();
?>

Anonymous   
Printed
Page 106
Replace call with definition, IE

"What?s wrong with this function definition?"

Anonymous   
Printed
Page 111
Example 6-4

Replace the # character with // and remove the blank line after it like this:
foreach ($shapes as $key => $value) { // every associative array has $key and $value pairs
The entire block is:
<?php
$shapes = array('Soda can' => 'Cylinder',
'Notepad' => 'Rectangle',
'Apple' => 'Sphere',
'Orange' => 'Sphere',
'Phonebook' => 'Rectangle');
foreach ($shapes as $key => $value) { // every associative array has $key and $value pairs
print "The $key is a $value.<br />";
}
?>

Anonymous   
Printed
Page 113
3 paragraph

"The assort() function works like sort"....

should read

"The asort() function works like sort"....

Anonymous   
Printed
Page 117
Last line

expand($array,EXTR_PREFIX_ALL,"the_prefix");

should be:

extract($array,EXTR_PREFIX_ALL,"the_prefix");

Anonymous   
Printed
Page 123
Add a note just after the code line ?mysql ?h hostname ?u user ?p?

Note: You may need to change directory to the location of the mysql binary, as it may not have been included in the system path.

Anonymous   
Printed
Page 125

GRANT ALL PRIVILEGES ON store.* TO 'michele'@'localhost' IDENTIFIED BY 'secret';

Would produce an error because database store doesn't exist (until the next page).

Add a note after ?GRANT ALL PRIVELGES ON store.* TO ?michele?@?localhost? IDENTIFIED by ?secret?;

Note: Run this command after creating the store database in the next section Creating a MySQL Database or an error occurs since the database hasn?t been created yet.

Anonymous   
Printed
Page 133
3rd paragraph, beginning "Example 7-1"

The line reads, "Example 7-1 creates the book table using the data types from Table 7-8."

There is no Table 7-8.
The text should say: Example 7-1 creates the books and authors tables using INT and VARCHAR data types.

Anonymous   
Printed
Page 137
last paragraph

The text on page 137:
To rename a column, use ALTER TABLE table new_column_name old_column_name definition new_column.

Should read (the CHANGE keyword is added and the order has been switched):

To rename a column, use ALTER TABLE table CHANGE old_column_name new_column_name definition_new_column.

Anonymous   
Printed
Page 138
change ?DROP TABLE test_table? to

DROP TABLE publications;
DROP TABLE authors;

Anonymous   
Printed
Page 138
Please move the section for Renaming a Table (on page 136) including Figure 7-10 to be after Removing a Column and before Deleting an entire table on page 138. So, Figure 7-11 becomes 7-10, 7-12 becomes 7-11, 7-13 becomes 7-12, 7-14 becomes 7-13, and 7-10

Anonymous   
Printed
Page 138
Before ?Querying the Database? add a note

Note: If you?ve executed the examples up to this point you?ve just deleted the sample database tables. To run the rest of the example in this chapter execute the create table scripts from Example 7-1 and populate the sample data by running Example 7-2.

Anonymous   
Printed
Page 139
top

You start with a few examples using the tables the reader had created (store.books, store.authors etc.)

SELECT * from books;

But we just had to change our tablenames and column definitions!
(See pages 136 - 138)
So books --> publications, authors.author --> authors.author_name.
Column books.pages is shown in all examples, but it has been deleted on page 138.

Examples on pages 139 - 144 are valid ONLY IF THE READER DID NOT CHANGE the original tables.

You may delete books and authors tables and rerun Example 7-1 before moving on to the Querying the Database section on page 138.

Anonymous   
Printed
Page 140
Example under "Specifying the order"

After typing SELECT * FROM authors ORDER BY author; at the mysql command prompt the table shows an extra author. Alex Martelli should not be in the results.

Anonymous   
Printed
Page 140
just before Example 7-3 add this note

Note: If you deleted the data for title_id = 1 in Deleting Database Data recreate that title by executing:
INSERT INTO books VALUES (1,"Linux in a Nutshell",112);
Before running the next two queries.

Anonymous   
Printed
Page 143

Deleting Database Data, should read:

DELETE FROM books where title_id = 1;

Anonymous   
Printed
Page 144
SELECT * FROM authors WHERE author LIKE "Aaron Webe_"

Should have a semicolon on the end like:
SELECT * FROM authors WHERE author LIKE "Aaron Webe_";

Anonymous   
Printed
Page 144
1st paragraph

The second sentence reads, "Notice that two % signs were used to surround the b, "&b&"."

It should read, "Notice that two % signs were used to surround the b, "%b%"." (Percentage characters
replacing the ampersands.)

Anonymous   
Printed
Page 197
Example 9-2 defines the variables with the db_ prefix.

These lines from Example 9-8 on page 197:
'username' => $username,
'password' => $password,
'hostspec' => $host,
'database' => $database
Should be:
'username' => $db_username,
'password' => $db_password,
'hostspec' => $db_host,
'database' => $db_database

Also in example 9-8 replace this line:
echo htmlentities($row['author ']) . '</td><td>';
With:
echo htmlentities($row['author']) . '</td><td>';

Anonymous   
Printed
Page 201
example 10-2

"</string" instead of "</strong>"

Anonymous   
Printed
Page 211
last

Example should be:
Example 10-6: Checking input from a radio button or a single select
<?php
$options = array('option 1', 'option 2', 'option 3');

// Coming from a radio button or single select statement
if (in_array($_GET['input'], $options)) {
echo "Valid";
} else
{
echo "Not Valid";
}
?>

Anonymous   
Printed
Page 216
example 10-10, lines 39 & 40

39 $search = htmlentities($GET["search"]);
40 $self = htmlentities($SERVER['PHP_SELF']);

should be:
39 $search = htmlentities($_GET["search"]);
40 $self = htmlentities($_SERVER['PHP_SELF']);

Anonymous   
Printed
Page 220
Please change the first line of code from

?php
to:
<?php

Anonymous   
Printed
Page 220
Example 10-11, 3rd line

$base_path = basename(dirname(__FILE__));

should be:

$base_path = dirname(__FILE__);

Anonymous   
Printed
Page 220
Example 10-11

Missing the initial angle bracket in the php declaration

Anonymous   
Printed
Page 220
Example 10-11

configs should be config (on the previous page, we were instructed to call the config directory config,
now it's being cites as config)

The line in Example 10-11,
$smarty->config_dir = $base_path.'/myapp/smarty/configs';

Should be (to match the text on the previous page):

$smarty->config_dir = $base_path.'/myapp/smarty/config';

Anonymous   
Printed
Page 229
2nd last line

should read:

"printf"

not "print"

Anonymous   
Printed
Page 232
1st paragraph, last sentence

Lastly, there is strops, which finds the position of every first occurrence of the string you specified.
Should read:
Lastly, there is strops, which finds the position of the first occurrence of the string you specified.

Anonymous   
Printed
Page 234
2nd image

should read:

12/13/05 16:18:01

since it is pm and "G" is hours in 24-hour format

Example 11-14 should read (to match the Figure):
<?php
$timestamp= time();
echo date("m/d/y g:i:sa",$timestamp);
?>

Anonymous   
Printed
Page 239
Please replace the line

The file exist.php does exist.
With:
file_exist.php does exist.
(note there is an underscore between file and exists)
Please replace the line:
As you would expect, the file does exist:
With:
Since the file that is being checked for is the name of the PHP script that?s running it naturally exists:

Anonymous   
Printed
Page 240
Replace

"The code tells you the many details regarding permissions on the file in Figure 11-17. "
with:
"The code tells you the many details regarding permissions on the file (assuming the running script is named permissions.php) in Figure 11-17."

Anonymous   
Printed
Page 244
middle of page

Change from:
As of PHP 4.01 you may use the global array $_FILES instead of $HTTP_POST_FILES.
To:
As of PHP 4.01 you should use the global array $_FILES instead of $HTTP_POST_FILES.

Anonymous   
Printed
Page 245-247
Please find and replace $HTTP_POST_FILES with $_FILES in code examples and regular text.

Anonymous   
Printed
Page 245
Please remove the line

unlink($HTTP_POST_FILES['upload_file']['tmp_name']);

Anonymous   
Printed
Page 246
Please align the text like this (notice the replaced $_FILES references as well)

move_uploaded_file($_FILES['upload_file']['tmp_name'],
"uploads/".$_FILES['upload_file']['name']);

Anonymous   
Printed
Page 249
Ex 11-29

<?php
exec(escapeshellcmd("df"),$output_lines,$return_value);
echo ("Command returned a value of $return_value.");
echo "</pre>";
foreach ($output_lines as $output) {
??? echo "$o";
}
echo "</pre>";
?>

Should be

<?php
exec(escapeshellcmd("df"),$output_lines,$return_value);
echo ("Command returned a value of $return_value.
");
echo "<pre>";
foreach ($output_lines as $output) {
??? echo "$output
";
}
echo "</pre>";
?>

Anonymous   
Printed
Page 263
Please replace the sentence

We?ve previously created the books and authors tables, but we haven?t created the purchases table.
With:
We?ve previously created the books and authors tables, if you ran Example 7-3, .
CHANGE THIS STATEMENT TO INDICDATE remove if ran 7-3.

Anonymous   
Printed
Page 270
3rd line of example 13-6

insert_db($title, $pages){
should be:
function insert_db($title, $pages){

the function keyword is on the line before in the comments!

Anonymous   
Printed
Page 270

code should read:

// Define a function to perform the database insert and display the titles
function insert_db($title, $pages){

Anonymous   
Printed
Page 287
Table 14-1, "secure" parameter

The Meaning column of Table 14-1 says that a "1" is used to indicate sending a cookie only over a secure HTTPS connection. The "Example value" column says that "0" is used for secure cookies. It can't be both.

The table should read:

Secure If set to TRUE, cookies are sent only over a secure HTTPS connection. HTTPS connections use encryption between the client and the browser to secure data. TRUE for secure and FALSE for insecure, which is the default.

Anonymous   
Printed
Page 299
Example 14-15 should be

unset ($_SESSION['username']);

Anonymous   
Printed
Page 334
In the middle of the code segment there is a missing } after $error=??: and an incorrect comment type <!-- -->)

Anonymous   
Printed
Page 347
last code line should be

Click to <a href="modify_posts.php?action=add">add</a> a posting.<br />

Anonymous   
Printed
Page 357
example 17-15 should read (modify_posts not modify_post)

<form action="modify_posts.php" method="POST">

Anonymous