Errata

Head First PHP & MySQL

Errata for Head First PHP & MySQL

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 16, 24
in PHP code examples

The report.html file saves the user's description of the aliens in a form field named "aliendescription". However, the report.php file tries to retrieve that information in variable $alien_description from $_POST['description'] whereas it *should* be $_POST['aliendescription'].

In the examples of the output from the PHP file execution, the description field is of course blank, because the description entered was not found by the PHP application. Oddly, this error has been corrected on page 22, but not pages 16 and 24.

You need to modify pages 16 and 24, substituting "aliendescription" for "description" in the PHP variable definition, and update the image of the PHP-generated confirmation on pages 13, 20 and 23 where the description field is blank.

Note from the Author or Editor:
On page 24, change
$alien_description = $_POST['description'];
to
$alien_description = $_POST['aliendescription'];

Also, images on 13, 20 and 23 where the Description field is blank need to have this value for the field:
little green men

Linda  Feb 18, 2009 
Printed
Page 16
First part of the PHP script (inside gray box)

Seventh Indian Reprint: July 2011 Edition. ISBN 13:978-81-8404-658-8

In the PHP script, "$alien_description = $_POST['description'];" should be "$alien_description = $_POST['aliendescription'];"

Note from the Author or Editor:
In the PHP script, 4th line in the gray box,
$alien_description = $_POST['description'];
should be
$alien_description = $_POST['aliendescription'];

Vignan Sampara  Sep 11, 2011 
Printed
Page 24 29 30 33 35 36
all examples of variable $fang_spotted on these pages

each code example of the variable $fang_spotted = $_POST['fangspotted'] doesn't end with a semi-colon

it is however mentioned earlier on in the example with a semi-colon on the end, and also in the downloadable code example.

Note from the Author or Editor:
Each occurrence of the line of code $fang_spotted = $_POST['fangspotted'] on pages 24, 29, 30, 33, 35, and 36 is missing a semicolon at the end of the line. They should have a semicolon as follows:

$fang_spotted = $_POST['fangspotted'];

Matt Worthington  Jan 15, 2009  Jun 01, 2009
PDF
Page 26
1st paragraph

One extra "are" in the first sentence.

Note from the Author or Editor:

Peter McDonald  Apr 18, 2009  Aug 26, 2011
Printed
Page 111
3rd paragraph

the "t" is missing in "execute", the book reads "execue".

Note from the Author or Editor:

Maristella  Oct 17, 2009  Aug 26, 2011
Printed
Page 125
first question of "there are no dumb questions"

one "e" is missing in "statement", the book reads "statment".

Note from the Author or Editor:

Maristella  Oct 18, 2009  Aug 26, 2011
Printed
Page 148
second 'sharpen your pencil' answer

The answer to the second question should be "33". The problem states that there are 23 customers with a first name of Anne, and 11 customers with a last name of Parker.

Therefore the number of customers with a first name of Anne will already include 'Anne Parker', and the or clause will only bring in 10 more records, those Parkers whose first name is not 'Anne'.

Note from the Author or Editor:
The second Sharpen Solution answer should be 33, not 34. The customer Anne Parker would already be counted in the 23 customers with a first name of Anne, and shouldn't be counted again in the 11 customers with a last name of Parker. So the total number of customers matching teh WHERE clause is 33, not 34.

Johny X  Jan 16, 2009  Jun 01, 2009
Printed
Page 154
Graphics

The file graphics cover up the file names below each graphic.

Dave Solomon  Jun 06, 2011  Aug 26, 2011
189
End of Test Drive Description

There's a question mark missing from the last sentence.

David Friedman  Jul 23, 2009  Aug 26, 2011
Printed
Page 210
first paragraph

the sentence "... only one *common* can be made the primary key" probably should be "... only one *column* can be made the primary key"

john  Jan 21, 2009  Jun 01, 2009
Printed
Page 256-257
connectvars.php code

The connection variables on pages 256-257 don't match up. So what is shown in connectvars.php on 256 for DB_PASSWORD and DB_NAME is different than what is shown as being included in index.php on 257.

Note from the Author or Editor:
The DB_PASSWORD and DB_NAME connection vars should be the same on 256 and 257. The example code aligns with the values on 256 but the specific settings aren't critical in this case because these are purely hypothetical database connection examples. The main thing is that they should match up from 256 to 257.

sanders kleinfeld  Dec 12, 2008  Jun 01, 2009
Printed
Page 269
top of code example

if ($_FILES['file']['error'] == 0) {

should be


if ($_FILES['screenshot']['error'] == 0) {

Shaya  Feb 01, 2009  Jun 01, 2009
PDF
Page 276
Caption under the HTML code

"Each piece of
data has a name
and a value, and
is separated from
other name/value
pairs by an
ampersand ($)."

But an ampersand is written & and not $.

Note from the Author or Editor:
In the annotation under the HTML code, change the dollar sign in parentheses

($)
to an ampersand

(&)

gabkdlly  Jul 19, 2012 
Printed
Page 286-289
removescore.php code

The screen shot image filename is not being sent along as part of the POST data, resulting in the screen shot image file on the server not being removed when a score is removed. The solution is to add a new hidden form field to the generated form using the following line of PHP code:

echo '<input type="hidden" name="screenshot" value="' . $screenshot . '" />';

And then initialize the $screenshot variable near the beginning of the script where the other POST data is being initialized. Use this line of PHP code:

$screenshot = $_POST['screenshot'];

Michael Morrison
Michael Morrison
 
Jan 09, 2009  Jun 01, 2009
Printed
Page 326
sharpen your pencil code

In this piece of code:

if ($row['approved'] == '0')
{
echo ' / <a href="approvescore.php?id=' . $row['id'] . '&date=' . $row['date'] .
'&name=' . $row['name'] . '&score=' . $row['score'] . '&screenshot=' .
$row['screenshot'] . THERE ARE DOUBLE QOUTES MISSING RIGHT HERE -----> '>Approve</a>';

It shouldbe '">Approve</a>';

Note from the Author or Editor:
The last line of the Sharpen Solution code is missing a double quote in the portion of the code with the Approve link. The last line of code should read like this:

$row['screenshot'] . '">Approve</a>';

Benjamin Groeneweg  Jan 18, 2009  Jun 01, 2009
Printed
Page 347
1st paragraph

It says in the first paragraph: "A database called mismatch_user is used...", but the database isn't called like that, the table within the database is. The name of the database is Mismatch in the book, and in the downloadable code for the book it is mismatchdb.

Note from the Author or Editor:
First paragraph, last sentence, "database" should be "table". So it should read:

"A table called mismatch_user is used to keep up with..."

Benjamin Groeneweg  Jan 18, 2009  Jun 01, 2009
Printed
Page 436
Last paragraph

"efficicient" should be "efficient".

Thomas Kennedy  Aug 18, 2010  Aug 26, 2011
Printed
Page 456
United States

Throughout Chapter 8, "SELECT topic_id FROM mismatch_topic ORDER BY category_id, topic_id" is used as the query to return the topic IDs. category_id does not exist in mismatch_topic. The column heading is category. Using category will make the query work.

Note from the Author or Editor:
Change "category_id" on 456 to read "category" instead.

Mike Griffin  Sep 26, 2011 
535
top of the page

The phrase "it's possible construct a single query" changed to "it's possible to construct a single query".

David Friedman  May 21, 2010  Aug 26, 2011
Printed
Page 544
first paragraph

'sarch' should be 'search'

DJPJ  Aug 28, 2009  Aug 26, 2011
Printed
Page 544
case 3: third blank to be filled

This is probably just a typo, but the written in answer on the third line I believe should be 5, not 3. The data location being accessed does not mention a date as it should, but the state.

Note from the Author or Editor:
Under the second case statement (case 3:), the third link generated should have an answer of 5, not 3. This is because this link is to sort by date, which is controlled in the code by the values 5 (ascending date) and 6 (descending date).

chris beaver  Jan 17, 2009  Jun 01, 2009
Printed
Page 594
3rd paragraph (last block of text)

It says to try out a few other variations, among one which is 707.827.7000, followed by how it should be noticed that the extra characters are removed. But the regex expression used does not remove the dots, only these characters: ( ) - \s.

Note from the Author or Editor:
The regular expression does not remove dots from a phone number, so "707.827.7000" would remain unaffected. You would need to alter the $pattern regular expression on the page to remove dots for this to work as explained.

Change the first phone number at the bottom of the page to use dashes instead of dots. So 707.827.7000 changes to 707-827-7000. If we want to keep them a bit more varied, you could also change the last number in that same list to use all spaces instead of the one dash. So 707 827-7000 would become 707 827 7000.

Benjamin Groeneweg  Jan 23, 2009  Jun 01, 2009
Printed
Page 598
Geek Bits

'distrubuted' should be 'distributed'.

Thomas Kennedy  Aug 20, 2010  Aug 26, 2011
Printed
Page 623
-

The download captcha for chapter 11 contains SHA(), while this should be SHA1(). It causes an error when trying to run.

Note from the Author or Editor:
On line 16 of the downloadable code for the captcha.php script, SHA should be sha1. The print version is OK.

Benjamin Groeneweg  Jan 23, 2009 
Printed
Page 715
Seventh row of table

The order of the arguments to the mysql_query() function are in the wrong order, and should be swapped. The correct form of the function is mysql_query(query, conn).

Note from the Author or Editor:
Should be changed as described in the errata submission.

Michael Morrison
Michael Morrison
 
Dec 15, 2008  Jun 01, 2009
Printed
Page 721
Step 1, Write Your Class

While declaring the function, "function song(...", the second argument is "$length". I expected it to be $lyrics.

Note from the Author or Editor:
The second argument to the Song() function should be $lyrics, not $length. So the first line of the function code should look like this:

function Song($title, $lyrics) {

Neil Mc  Jan 14, 2009  Jun 01, 2009
Printed
Page 733
1st paragraph

Misspelled "browser" and "your". "..., open a brower window..." and "... alive and well on you local machine."

Anonymous  May 15, 2011  Aug 26, 2011
Printed
Page 746
Last paragraph

The first letter of the paragraph (the "I" in "Insert") is not bolded while the rest of the paragraph is bolded.

Dave Solomon  May 27, 2011  Aug 26, 2011