Errata

PHP & MySQL: The Missing Manual

Errata for PHP & MySQL: The Missing Manual

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 210
Near the bottom of the html code example

In the code example, Brett adds the form html to upload a file, but forgets to add the "<br />" at the end of the second new line, which causes the page to display all wonky, making it not look like the example on 211. Minor error.

Note from the Author or Editor:
I'm not seeing this error in my printed copy of the book. However, it is correct that all opening double-quotation marks should be matched up with closing double-quotation marks.

John Foster  Jul 27, 2013 
PDF
Page 246
2nd paragraph

Error is here:

"So, can you get your error handling to be that elegant? It's worth at try."

Should be "It's worth a try."

Note from the Author or Editor:
Thanks!

haitiman  Jul 11, 2013 
PDF
Page 233
2nd paragraph under Figure 8-7

You do need to make one fix, though: that backslash following up before a single apostrophe ("There\'s" in the first sentence) is no good.

There is an error in this statement if you are testing this on your own machine. If you enter the following from page 232 using localhost in place of www.yellowtagmedia.com, you will not get a backslash when you test:

http://www.yellowtagmedia.com/phpMM2/ch08/scripts/show_error.php?error_message=There%27s%20been%20a%20problem%20connecting%20to%20the%20database

I don't know whether this a PHP problem or if the author forgot to include the backslash in the above statement. Nevertheless, it was a cause of frustration and multiple rereads. This needs to be corrected.

Note from the Author or Editor:
You're right. The value for the error_message request parameter should be

There%5C%27s%20been%20a%20problem%20connecting%20to%20the%20database

(The %5C adds the \ that is missing.)

haitiman  Jul 11, 2013 
Printed, PDF
Page 394
In code

Constants (VALID_USERNAME & VALID_PASSWORD) not being defined with correct syntax. These should be in quotes.

Page shows
define(VALID_USERNAME, "admin");
define(VALID_PASSWORD, "super_secret");

Should be
define("VALID_USERNAME", "admin");
define("VALID_PASSWORD", "super_secret");

Note from the Author or Editor:
Absolutely correct. Thanks for finding this...

David Forshaw  Jun 19, 2013 
Printed
Page 42
Paragraph just after the figure

A period is missing from the end of the second sentence in this paragraph.

Note from the Author or Editor:
Thanks!

Jesse Heines  Jun 05, 2013 
Printed
Page 21
Next-to-the-last line of the paragraph that starts with "Both choices..."

"Note only that, ..." should be "Not only that, ..."

Jesse Heines  Jun 05, 2013 
Printed
Page 17
Figure 1-2

This figure shows two arrows going to the displayed page, one from the HTML rendered and one from the CSS renderer. This is not conceptually correct. The output of the two renderers should be combined as they are in Figure 1-3 and a single arrow should go into the displayed page, again as in Figure 1-3.

Note from the Author or Editor:
Completely agree with you here. I'd love to say that this was a figure translation issue (I draw all my figures by hand and the wonderful folks at O'Reilly translate them to something digital), but I can't find my originals, so I'll say it must have been me :-)

Either way, you're right, the browser handles all this through one process from the perspective of this diagram.

Thanks.

Jesse Heines  Jun 05, 2013 
Printed
Page 48
Up To Speed - Directory Assistance

The images referenced in the downloaded phpMM.css aren't pulling up when I open "sayHelloWeb.HTML". I get the green background, so apparently it is finding the CSS file, but it can't find the images referenced in the CSS file.

Here's one of the problem lines in the CSS file:

background: #75bb45 url('/phpMM/images/tmm_php-mysql_background.png') repeat-y;

The downloaded directory structure does not include the directory "phpMM".

I had my "images" folder in the same directory as my "sayHelloWeb.HTML" file. I fixed the problem by moving my "images" folder into the "css" folder. Now the relative URL works.

Summary: The printed instructions say to have the "images" directory at the same level as the same HTML file as well as the "css" directory. It won't work unless the "images" directory is inside the "css" directory.

Note from the Author or Editor:
Hi. The directory structure on the Missing CD provides lots of "in progress" snapshots, essentially giving you the code at every step of the book's major headings. However, this has created some confusion in terms of final file locations.

I'm working on an additional set of downloads that give you the final version of the code--as it would run--that should clear this up. Look for that in the next few days. Thanks for reporting this, and I'm working on it. My apologies for the confusion.

Thanks
Brett

William Young  Apr 14, 2013 
Printed
Page 98
3rd paragraph / Numbered List

As someone with zero experience with Mac's "Terminal" app, this section was kind of confusing:

"SET UP MYSQL FOR YOUR USER PROFILE
You can make this easier with a few quick edits to your profile and setup..."

I followed the list of steps [best I could] but was not able to create a shortcut.

Steps 5 and 6 are the lines that seem unclear to me:

" 5. Find or add a line to update your PATH variable "

" 6. Now save your .bash_profile, and restart Terminal. "

A few screen shots or a box with a more detailed explanation would be really helpful.

Note from the Author or Editor:
Hi there. As an example, here's the line setting my profile on one of my systems for Mac:

PATH="/Users/bdm0509/Developer/bin:/Users/bdm0509/Developer/Cellar/python/2.7.1/bin:/Users/bdm0509/Developer/share/python:/Users/bdm0509/Developer/sbin:$PATH":/Users/bdm0509/bin; export PATH

You're right that the section in question moves sort of fast. I probably need some references to other Mac-related TMMs. It's hard to get into too much detail without bogging down, while still providing enough to keep you moving. We can look at adding those references and more examples in a future edition.

Hope this line of example helps.

-Brett

Tamahl Gorham  Mar 30, 2013 
ePub
Page 435
First to code snippets

On show_user.php:

$user_id = $_REQUEST['user_id'];

does not work using a local mamp stack with Chrome. The user_id is not read from the browser cookie. If you change to:

$user_id = $_COOKIE['user_id'];

everything works fine. I read online that PHP 5.3 by default excludes cookies from $_REQUEST. It took about an hour to track down the problem, will likely be an issue for others as well.

Great book by the way, I rated it highly on Amazon. Thanks!

Note from the Author or Editor:
Hmmm. That's new to me. The book uses PHP 5.2.17, and doesn't have the issue with $_REQUEST excluding $_COOKIE. Bummer.

Ok, so in show_user.php on p. 435, we should have:

$user_id = $_COOKIE['user_id'];

instead of

$user_id = $_REQUEST['user_id'];

That's a little more specific, which makes the code clearer, and will still work on older versions of PHP as well.

Thanks for your help findong this!

Anonymous  Mar 11, 2013 
PDF
Page 86
3/4 down the page

"This is repeated until there are no more values from left in the array." Should have "from" removed.

Note from the Author or Editor:
Thanks!

Cole Jackowski  Mar 10, 2013 
PDF
Page 21
Note box

"...you want to have both a way to use OF PHP and MySQL..." Should have the "of" removed.

Note from the Author or Editor:
Thanks!

Cole Jackowski  Mar 08, 2013 
Printed
Page 75
3rd paragraph, toward the end of listed item 3

The text says "add the handle to the beginning of $twitter_url."
It should say "add the handle to the end of $twitter_url."
The following page, page 76, correctly states this in paragraph 5 when it says: "If there is no @, this code simply adds the handle to the end of $twitter_url"

Note from the Author or Editor:
Good catch, thanks. So on 75, change "add the handle to the beginning of $twitter_url." to "add the handle to the end of $twitter_url."

Thanks for the help!

Anonymous  Feb 26, 2013 
Printed
Page 212
3rd line of code segment

in the code segment:

$insert_sql = "INSERT INTO users (first_name, last_name, email, bio," . "facebook_url, twitter_handle) " .
"VALUES ('{$first_name}', '{$last_name}', '{$email}','{$bio}' " .
"'{$facebook_url}','{$twitter_handle}');";

a comma ( , ) is missing in the 3rd line after {$bio}. Should be:

{$bio}', " .

Note from the Author or Editor:
Good catch. Those line feeds we have to insert for the book are no fun. You're right, this line on page 212 should be:

$insert_sql = "INSERT INTO users (first_name, last_name, email, bio," .
"facebook_url, twitter_handle) " .
"VALUES ('{$first_name}', '{$last_name}', '{$email}', '{$bio}', " .
"'{$facebook_url}', '{$twitter_handle}');";

Rick  Feb 06, 2013 
PDF
Page 182
Code Segment 6th line

In the code segment, 6th line has error as printed in the book:
$facebook_url = str_replace("facebook.org", "facebook.com", trim($_
REQUEST['facebook_url']));

because of this line break, string $_REQUEST is considered as to words "$" and "_REQUEST".
Solution: shift the line break as:
$facebook_url = str_replace("facebook.org", "facebook.com",
trim($_REQUEST['facebook_url']));

Note from the Author or Editor:
The best solution here is to simply not introduce a line break at all on local systems. I mention that in several spots, but it can be a problem.

In the book, let's change the code to read (as suggested):

$facebook_url = str_replace("facebook.org", "facebook.com",
trim($_REQUEST['facebook_url']));

That provides the least room for misunderstanding.

Thanks!

Anonymous  Jan 24, 2013 
PDF
Page 216
show_user.php code

I go an undefined variable error when running the code as it is printed - specifically "$position" for the turning twitter_handle into a url.

I had to add $position = strpos($twitter_handle, "@"); before the "$twitter_url = ..." line.

Was that required, or was I missing something else?

Note from the Author or Editor:
Well, that may be an error resulting from using show_user.php directly, without it being redirected from create_user.php. When create_user.php redirects, I believe PHP (most versions) keep up with $position, which is defined in that script.

You're right, though, a better approach would be to ensure it's set with:

$position = strpos($twitter_handle, "@");

--inserted right before:

$twitter_url = "http://www.twitter.com/" .
substr($twitter_handle, $position + 1);

This should be changed here, on p. 216.

Thanks, and nice catch.

Sean Conley  Jan 24, 2013 
PDF
Page 149
6th line of code segment on page

in the code segment

if ($result) {
echo "<p>Your query was processed successfully.</p>"
echo "<p>{$query_text}</p>";
}

the echo statements if not terminated.

Add ";" the this. The segment should read:

if ($result) {
echo "<p>Your query was processed successfully.</p>";
echo "<p>{$query_text}</p>";
}

Note from the Author or Editor:
Nice catch. Yes, there should be a semicolon there, as you suggest.

Thanks.

Sachin Sharma  Jan 23, 2013 
Printed, PDF
Page 242
bottom heading

In the section titled "Redirecting on Error", the subsection is titled "Update connect.php to show_user.php".

It should instead be titled "Update connect.php to show_error.php" since this is the purpose of the subsection. There is no mention of show_user.php.

Note from the Author or Editor:
Thanks!

Anonymous  Jan 21, 2013 
PDF
Page 41
4th Line

The text as written in book
"Now, go to the directory in which you saved your program, sayHello.php. You can do a
directory listing with dir (in Windows) or ls (on the Mac) to ensure that you?re in the
right directory. Once you?re in the right directory, type this into your command line:
php sayHello.php"

The program will not run in windows. Because when I run the program, from folder/directory in which I have saved my programs(E:\wamp\www\SS in my case) is separate from the folder/directory in which the php.exe lies (E:\wamp\bin\php\php5.3.13 in my case) and the folder/directory containing php.exe(in my case the pathb is E:\wamp\bin\php\php5.3.13) is not on the default path. So we will either have to supply the complete path
E:\wamp\bin\php\php5.3.13\php.exe sayHello
to run the program or we will have to add
E:\wamp\bin\php\php5.3.13

to default path.

Note from the Author or Editor:
Hmmm. I'm not sure how, but somewhere along the way from 1st edition to 2nd, we lost some of the explanatory boxes about setting your PATH environment variable to include PHP. You're right, of course, you need that to work.

Thanks for the clarification. In a future edition we'll try and resolve this in the text.

Sachin Sharma  Jan 17, 2013 
PDF
Page 19
code segment, 4th line

--------------------------------------------------
<html>
<head>
<link href="../../css/phpMM.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header"><h1>PHP & MySQL: The Missing Manual</h1></div>
<div id="example">Example 1-1</div>
<div id="content">
<h1>Hello, <?php echo $_REQUEST['name']; ?></h1>
<p>Great to meet you. Welcome to the beginning of your PHP programming odyssey.</p>
</form> <!-- THE WRONG PART -->
</div>
<div id="footer"></div>
</body>
</html>
--------------------------------------------------
form tag has been used without using its opening counterpart. Although it does not have any effect on code, but is semantically wrong.

Note from the Author or Editor:
I believe this is actually the first edition, but the best solution is simply to remove the </form> tag altogether.

Sachin Sharma  Jan 16, 2013 
Printed
Page 7
1st and 3rd paragraph under What is MySQL heading.

At the end of the 1st paragragh in this section, the sentence currently reads: "And, it has thousands of developers that at some point have helped improved its code base." The tense of the word should simply be improve, since the verb "helped" is already in the past tense.

Finally, in the last sentence of the 3rd paragraph in this section, the sentence currently reads, in part,: "use functions that let PHP scripts to do just about anything . . ." I think the word "to" should be dropped/omitted. Then the sentence would read: let PHP scripts do just about anything . . .

Thanks,
Will Garland

Note from the Author or Editor:
Thanks!

Will Garland  Jan 08, 2013