Errata

Learning PHP, MySQL & JavaScript

Errata for Learning PHP, MySQL & JavaScript

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
Safari Books Online
Ch17
Example 17-2. urlpost.html

Coded HTML does not work at present

Currently text says:
params = "news.com"

It needs to say:
params = "url=news.com"

The text describing the example refers to setting params to the name/value pair that will be posted to the PHP that responds to it.

Note from the Author or Editor:
This was fixed during production.

Anonymous  Jan 07, 2018  May 08, 2018
Safari Books Online
Ch18
15th paragraph

Under the section "Using Classes"

Problem: Missing apostrophe or sentence needs rewriting in the first sentence.

The first sentence:
The value of an id element must be unique within the web page, because that what lets it serve as an identifier.
===

Should be:
The value of an id element must be unique within the web page, because that's what lets it serve as an identifier.
====

(I've underlines it, if you look at the text in a fixed width font.)

Note from the Author or Editor:
This was fixed during production.

Anonymous  Jan 08, 2018  May 08, 2018
PDF
Page 24-22
Example 24-22 Manipulating image data.html

Robin Nixon/5th_edition_examples/24/example24-22.html
Please advise how to make the manipulated image display in Firefox 71(32 bit) and Opera 55 on Windows 7?

The manipulated image in example24-22.html works in Internet Explorer 11.09600.19572 and k-meleon K-Meleon/76.0; however, it’s suppressed in Firefox 71(32 bit) and Opera 55, on Windows 7: only the lightblue canvas shows up to the right of the original image

Console log / debugger states : SecurityError: The operation is insecure. example24-22.html:21; debugger points to idata = context.getImageData(0, 0, myimage.width, myimage.height).

A search on the internet -> https://developpaper.com/explain-how-to-solve-the-cross-domain-problem-of-canvas-image-getimagedata-todataurl/ -> states use AJAX, which seems a complex way of resolving the problem

Please advise how to make the manipulated image display in Firefox 71(32 bit) and Opera 55 on Windows 7?

Many thanks

Note from the Author or Editor:
For this to work correctly, please add the line following directly after myimage.src = 'photo.jpg' in example 24-22:

myimage.crossOrigin = ''

Then please add to the end of the final paragraph on page 626 the following:

Many recent browsers have adopted strict security measures to prevent cross origin exploits, which is why we have to add the crossOrigin attribute with a value of the empty string (representing the default of 'anonymous') to the myimage object in this example, to expressly allow the image data to be read. For the same security reasons, the example will only work correctly when served from a web server and will not work correct when called from a local file system.

Nevil  Dec 24, 2019  Jul 31, 2020
Printed
Page 26
First paragraph under "Installing AMPPS on macOS"

URL given for downloading AMPPS is apachefriends.org (which is URL for XAMPP not AMPPS).

Note from the Author or Editor:
Correct the URL should be: https://www.ampps.com

Anonymous  Jul 14, 2019  Aug 09, 2019
Printed
Page 28
Under the 'Installing LAMP on Linux' Section

The text tells you to download the linux version of AMPPS from apachefreinds.org. This is wrong as this the the home of XAMPP. I assume this was used in the previous addition and it was missed during checking for the new version.

Note from the Author or Editor:
Correct. The URL is:

https://www.ampps.com

Peter Jones  Dec 28, 2018  Aug 09, 2019
Printed
Page 30
2nd paragraph

Editra site is no longer available since July 2019:
https://en.wikipedia.org/wiki/Editra

Note from the Author or Editor:
Starting at line 3 of the final paragraph on P30, the text relating to Editra should now read as follows, without the end of the sentence about downloading and locating the documentation.

At the time of writing Editra development appears to have been discontinued, but you can download the last known fully working release for free at https://editra.en.softonic.com.

Charles  Sep 04, 2019  Jan 10, 2020
Printed
Page 46
Table 3-3

Last three rows of Table 3-3, in the Description column, repeat the word "to":

<> Is not equal to to
=== Is identical to to
!== Is not identical to to

Note from the Author or Editor:
In Table 3-3 on P46 the final three rows have an extraneous word 'to' in non italics added at the end of the middle column text, which should be removed.

Jeff  Oct 11, 2019  Jan 10, 2020
Printed
Page 60
Example 3-18

the statement is incorrect

static $int = 1+2; //Disallowed (will produce a parse error)

As per PHP 5.6

static $int = 1+2; // correct (as of PHP 5.6)

reference:

https://www.php.net/manual/en/language.variables.scope.php

Thanks

Luca Sabato

Note from the Author or Editor:
Correct. Please replace:

static $int = 1+2; //Disallowed (will produce a parse error)

With:

static $int = 1+2; // correct (as of PHP 5.6)

Luca Sabato  May 30, 2019  Aug 09, 2019
Printed
Page 90
2nd paragraph

variable $j should be set to 11 in order to satisfy "For all values of $j between 10 and -10..." (as $j is decremented before the echo statement runs).

Steve Benson  Mar 16, 2019  Aug 09, 2019
Printed, ePub
Page 104
Last Sentence

“Example 5-9 checks for array_combine, a function specific to PHP version 5.”

Excerpt From: Robin Nixon. “Learning PHP, MySQL & JavaScript.” Apple Books.


The PHP user manual page at
https://www.php.net/manual/en/function.array-combine.php seems to indicate that the function mentioned in the text is available in the current version of PHP.

Note from the Author or Editor:
This should now read:

Example 5-9 checks for array_combine, a function specific to only some versions of PHP.

MHauser  Mar 01, 2020  Jul 31, 2020
PDF
Page 128
Middle

The author suggests, as "an alternative syntax to foreach...as, you can use the list function in conjunction with the each function"

However, according to

https://www.php.net/manual/en/function.each.php

The 'each' function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.

Note from the Author or Editor:
Yes. This advice is no longer accurate and should be ignored.

Marc  Mar 14, 2020  Jul 31, 2020
Printed
Page 160
bottom

Regarding:

$name = strtolower(ereg_replace("[^A-Za-z0-9.]", "", $name));

The ereg function was deprecated in PHP 5.3.0, and removed in PHP 7.0.0.

https://www.php.net/manual/en/function.ereg.php

Note from the Author or Editor:
This is a typo. The statement should read as follows:

$name = strtolower(preg_replace("[^A-Za-z0-9.]", "", $name));

Denisovan  Mar 07, 2020  Jul 31, 2020
Printed
Page 174
Creating Users

“To create a user, issue the GRANT command”

Beginning with MySQL 8.0 you can no longer use the GRANT command to create a user. Use the CREATE USER statement instead.

https://dev.mysql.com/doc/refman/8.0/en/create-user.html

Note from the Author or Editor:
Yes. This is correct as of MySQL 8.

The book should read:

To create a user, issue the CREATE USER command which takes the following form (don’t type this in; it’s not an actual working command):

CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';
GRANT PRIVILEGES ON database.object TO 'username'@'hostname'

Denisovan  Mar 07, 2020  Jul 31, 2020
PDF
Page 198
2nd paragraph

3rd line: "Because and is a stopword"

'and' is stopword for MyISAM search index. But we are (as instructed in the book) using here InnoDB seach engine where 'and' is not a stopword.
Check:
https://dev.mysql.com/doc/refman/8.0/en/fulltext-stopwords.html#fulltext-stopwords-stopwords-for-innodb-search-indexes

Note from the Author or Editor:
Replace the sentence:

Because and is a stopword, MySQL will ignore it and the query will always produce an empty set - no matter what is stored in the columns

With:

If you are using the MyISAM storage engine, then because and is a stopword in that engine, MySQL will ignore it and the query will always produce an empty set - no matter what is stored in the column. Otherwise, if you are using InnoDB and is an allowed word.

Tomi Halonen  Jul 02, 2019  Aug 09, 2019
Printed
Page 243
Example 10-6

Referring to this code, in example 10-6

if (isset($_POST['author']) &&
isset($_POST['title']) &&
isset($_POST['category']) &&
isset($_POST['year']) &&
isset($_POST['isbn']))

pg. 245 states "The first section of new code [shown above] starts by using the isset function to check whether values for all the fields have been
posted to the program. "

isset returns true when no value is submitted in the form. isset only triggers when the value being checked is NULL. To fix it, you can replace all the isset tests with !empty (not empty) so you can actually check whether values for all the fields have been filled in by the user before the user tries to write empty, garbage data to the database. The isset check, as it is currently written, checks for nothing at all, as far as I can tell.

Kyle Benjamin  Jul 23, 2019  Aug 09, 2019
Printed
Page 269
Example file: example11-2.php

Not sure if intentional or an error:

Line 12 in the example file (example11-2.php):

form method="post" action="formtest.php"

Should be:

form method="post" action="formtest2.php"

formtest2.php - matches the example printed in the book

Note from the Author or Editor:
Fixed in the downloadable examples to match the book.

Anonymous  Feb 21, 2019  Aug 09, 2019
Printed
Page 269
Example 11-2

The following code:

if (isset($_POST['name'])) $name = $_POST['name'];
else $name = "(Not Entered)";

will only produce the text (Not Entered) upon running the first time. Any subsequent entry of nothing in the text box (i.e., leaving the field blank and clicking Submit) will not produce the text (Not Entered).

The following code remedies this:

if (!empty(($_POST['name']))) $name = $_POST['name'];
else $name = "(Not Entered)";

Note from the Author or Editor:
The first two lines of Example 11-2 on P269 should be...

if (!empty(($_POST['name']))) $name = $_POST['name'];
else $name = "(Not Entered)";

Jeff  Nov 06, 2019  Jan 10, 2020
Printed
Page 301
Ex12-6

The second to last line of code in continue.php is the following:

else echo "Please <a href=authenticate2.php>Click Here</a> to log in.";

Unlike other <a> tags in the book, the href here (authenticate2.php) is not in single quotes.

Note from the Author or Editor:
Although not an error, for consistency the final line of code on P301 (prior to the closing ?> ) should be

else echo "Please <a href='authenticate2.php'>Click Here</a> to log in.";

Jeff  Nov 17, 2019  Jan 10, 2020
Printed
Page 303
Example 12-8

The first if statement in Example 12-8 is the following:

if (isset($_SESSION['username']))

However $_SESSION['username'] was never previously set. It was $_SESSION['forename'] that was set.

The first if statement in Example 12-6 correctly uses $_SESSION['forename'], which I believe should be used in Example 12-8 (which itself is a tweak of Example 12-6).

Also, Example 12-8 uses an echo statement combined with the htmlspecialchars function, which results in the program literally outputting .<br> on the screen.

Note from the Author or Editor:
Example 12-8 should be replaced with this:

<?php
session_start();

if (isset($_SESSION['forename']))
{
$forename = $_SESSION['forename'];
$surname = $_SESSION['surname'];

destroy_session_and_data();

echo htmlspecialchars("Welcome back $forename");
echo "<br>";
echo htmlspecialchars("Your full name is $forename $surname.");
}
else echo "Please <a href='authenticate.php'>click here</a> to log in.";

function destroy_session_and_data()
{
$_SESSION = array();
setcookie(session_name(), '', time() - 2592000, '/');
session_destroy();
}
?>

Jeff  Nov 18, 2019  Jan 10, 2020
Printed
Page 304
First sentence under heading "Preventing session hijacking

Sentence states the following:

When SSL is not a possibility....

This was correct in Ed. 4 of this book. In Ed. 5, the concept of TLS (the successor to SSL) is being discussed. Therefore to be more consistent, the sentence should read as follows:

When TLS is not a possibility...

Note from the Author or Editor:
The first sentence of the third paragraph of P304 should read

When TLS is not a possibility...

Jeff  Nov 19, 2019  Jan 10, 2020
Printed
Page 305
Last paragraph, first sentence.

Last paragraph, first sentence reads as follows:

Press Reload a few times here, and you should see it count up again from 0.

Perhaps I'm not understanding the navigation instructions correctly, but the counter never seems to return to zero. It keeps on ever incrementing by one with each Reload.

Note from the Author or Editor:
The first sentence of the final paragraph on P305 should read

Press Reload a few times here, and you should see it continue counting upwards.

Jeff  Nov 19, 2019  Jan 10, 2020
PDF
Page 399
Example 17.2 <script>

The following lines of code need removing from the script else the browser will refuse to set them and throw an error

request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");

XMLHttpRequest isn't allowed to set these headers, they are being set automatically by the browser. The reason is that by manipulating these headers you might be able to trick the server into accepting a second request through the same connection, one that wouldn't go through the usual security checks - that would be a security vulnerability in the browser.

Note from the Author or Editor:
Yes, these two lines should be removed from the Example

Malenko  Sep 01, 2019  Jan 10, 2020
Printed
Page 491
Example 20-8

In Chrome and Brave, the code for Example 20-8 never forces a DOM refresh, and therefore the new element with contents "I'm a new object inserted in the DOM" never appears on screen.

(The code for Example 20-8 DOES work in Firefox and Internet Explorer.)

Note from the Author or Editor:
The final paragraph on Page 491 should have the following appended to its end:

In Chrome-based and some other browsers you may see pop-up windows asking whether you wish to confirm the insertion and removal of the element.

Jeff  Feb 06, 2020  Jul 31, 2020
Printed
Page 600, 601
last line on p. 600 and on fourth and fifth lines on p. 601

textBaseLine should be textBaseline

John Singleton  Jul 03, 2020  Jul 31, 2020
Printed
Page 722
Answers 2 and 3 (Chapter 12)

Answers 2 and 3 (page 722) use the term "set_cookie".
Chapter 12 (pages 289-290) uses the term "setcookie".

I couldn't find "set_cookie" in the PHP manual.

Note from the Author or Editor:
Answers 2 & 3 on P722 should replace set_cookie with setcookie

Jeff  Nov 19, 2019  Jan 10, 2020