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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

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

Version Location Description Submitted by Date submitted
Printed Page Page 435
Alternative for $_REQUEST['user_id'] or $_COOKIE['user_id']

I saw the posting that says you can change $_REQUEST['user_id'] to $_COOKIE['user_id']. As an alternative, you can change your php.ini file (typically located at /etc/php5/apache2), altering all references to request_order = "GP" to request_order = "GPC". This will include cookies in $_REQUEST.

Ira Brickman  Mar 16, 2015 
Printed Page 1
United States

I am having the same issue as: Teo Maroulis (Oct 01, 2013). If show_users.pph is not redirected, $_REQUEST['success_message'] will expect a value and will have an index error. And as Teo Maoulis pointed out and from my own findings, isset($_REQUEST['success_message'] has to be checked first before calling page_start($_REQUEST['success_message'];

Anonymous  Nov 07, 2013 
Printed Page 4
code example, HTML <body><div id="header">

This problem begins with the example on p. 4, but also occurs with almost every PHP example in the text.

HTML interprets the ampersand as a special character. Therefore, Eclipse (Kepler SR2) throws up the following warning:

---- Eclipse warning message ----
Invalid character used in text string (PHP & MySQL: The Missing Manual).
---- end Eclipse warning message ----

for every instance of the textbook title included in PHP code.

FIX: Change the header to:

<h1>PHP &amp; MySQL: The Missing Manual</h1>

throughout the text and the example code.

Dave Ross  Oct 22, 2014 
PDF Page 38
code sample

wrong example:

<?php
echo "Hello there. So I hear you're learning to be a PHP programmer!\n";
echo "Why don't you type in your name for me:\n";
$name = trim(fgets(STDIN));
echo "\nThanks, " . $name . ", it's really nice to meet you.\n\n";
?>

right example:
<?php
define('STDIN',fopen("php://stdin","r"));
echo "Hello there. So I hear you're learning to be a PHP programmer!\n";
echo "Why don't you type in your name for me:\n";
$name = trim(fgets(STDIN));
echo "\nThanks, " . $name . ", it's really nice to meet you.\n\n";
?>

Anonymous  Nov 17, 2014 
PDF Page 48
first "Note:"

The note reads: You can download this HTML, along with the rest of the book’s sample files, from www.missing
manuals.com/cds/phpmysqlmm2e.
And the underlying code for the link is: http://www.missing%20manuals.com/cds/phpmysqlmm2e
Thus creating an incorrect URL; therefore, no access to that URL is possible. The "%20" must be eliminated.

Henry Gutierrez  Jun 12, 2015 
PDF Page 80
United States

On this page of the pdf, the author introduces the string replace function within this code segment.

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

$position = strpos($facebook_url, "facebook.com");
if ($position === false)
{
$facebook_url = "http://www.facebook.com" . $facebook_url;

}

The problem here is not the coding, but the end result. The str_replace function kicks in if a user enters facebook.org instead of facebook.com. The error doesn't rear its ugly head until the logic portion of the code.

What ever the user enters gets appended to either the end of current host directory or "http://www.facebook.com." So you may end up with results like:

www.facebook.com/facebook.com/username
or
localhost/phpMySQL/chptr3/facebook.com/username

This is not a serious problem to a seasoned coder, but can be frustrating to a novice. Perhaps this code may help.

$facebook_url = str_replace("facebook.org","facebook.com", trim($_REQUEST['facebook_url']));
$position = (strpos($facebook_url, "www.facebook.com") xor strpos($facebook_url, "facebook.com"));
if ($position)
{
$facebook_url = "http://" . $facebook_url;

}
else
{
$facebook_url = "http://" . $facebook_url;
}

haitiman  Sep 19, 2013 
Printed Page 80
code example

I get a similar result to that reported by haitiman on 9/19/2013. The facebook link produced by the code on page 80 looks like this when I hover the cursor:

http://localhost:8888/PHPMySQLMissingCD/scripts/www.facebook.com/example_name

When I click the link, I get a 404 'not found' error: "The requested URL /PHPMySQLMissingCD/scripts/www.facebook.com/examplename was not found on this server."

I also tried coding each step separately as described in the box on page 81:

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

This produced the same result.

I'm a beginner, so this is pretty frustrating.

Please provide corrected code.

Also, why does the link which produces that error appear to be fine in the page source code? (i.e. www.facebook.com/examplename)

Bob  Oct 21, 2013 
Printed Page 80
Figure 3-9 screenshot - Facebook URL text input

The line above figure 3-9 states "and a bad facebook.org URL, as shown in Figure 3-9."

The typo is in the Facebook URL supplied in figure 3-9's screen shot. It is supposed to have facebook.org so the script can correct it, not facebook.com as shown.

Anonymous  Jan 18, 2017 
PDF Page 84
2nd block of Programm code

The code reads:

<?php

$file_cabinet['first_name'] = "Derek";
$file_cabinet['last_name'] = "Trucks";
$file_cabinet['email'] = "derek@DerekTrucks.com";
$file_cabinet['facebook_url'] = "http://www.facebook.com/DerekTrucks";
$file_cabinet['twitter_handle'] = "@derekandsusan";

$first_name = $file_cabinet['first_name'];
$last_name = $file_cabinet['last_name'];
$email = $file_cabinet['email'];
$facebook_url = $file_cabinet['facebook_url'];
$twitter_handle = $file_cabinet['twitter_handle'];


echo $first_name . " " . $last_name;
echo "\nEmail: " . $email;
echo "\nFacebook URL: " . $facebook_url;
echo "\nTwitter Handle: " . $twitter_url;

?>

If you run that code, you will get an undefined variable "twitter_url" error on line 19 (the very last one). The correct code must be changed from "$twitter_handle = $file_cabinet['twitter_handle'];" on line 13 to "$twitter_url = $file_cabinet['twitter_handle'];"

Henry Gutierrez  Jun 13, 2015 
PDF Page 84
2nd block of Programm code

Previously reported errata is NOT on the pdf version but instead within the code supplied as part of the file enclosed in "PHPmm2e_ch03_examples.zip".

Excuse the missinterpretation.

Henry Gutierrez  Jun 13, 2015 
PDF Page 103
2nd paragraph

It reads: "You do this be replacing"... while it may be "You do this by replacing"...

HenryGR  Jun 14, 2015 
Printed Page 117
1st paragraph

the (!$result) code block is clearly running , that's why error statement is displayed and not the while statement is displayed ..

ashish kumar  Aug 16, 2013 
Printed Page 121

in NOTE box, if trying to run locally as sam computer as php and we-serving files database host is localhost, but what is username and password? How we we find that out, or if optional would we just provide one parameter to mysql_connect ("localhost") or mysql_connect("localhost",,)

Anonymous  Jan 23, 2014 
Printed, PDF Page 145
After the note

Good afternoon!
It does not work on the server script-script from the book PHP & MySQL: The Missing Manual by Brett McLaughlin, lesson Chapter 4. Connecting PHP to MySQL.
Error in line 13 - $result = mysql_query("SHOW TABLES;"); I want to ask you what is wrong, how to fix the error? What is there in the syntax?

<?php
mysql_connect("localhost", "111_111", "")
or die("<p>Ошибка подключения к базе данных: " .
mysql_error() . "</p>");

echo "<p>Вы подключились к MySQL!</p>";

mysql_select_db("base")
or die("<p>Ошибка при выборе базы данных 1111: " .
mysql_error() . "</p>");
echo "<p>Вы подключены к MySQL с использованием базы данных base.</p>"

line 13: --- $result = mysql_query("SHOW TABLES;"); --- The interpreter writes that there is an error in the syntax. What could be the problem? How to write correctly?

if (!$result) {
die("<p>Ошибка при выводе перечня таблиц: " . mysql_error() . "</p>");
echo "<p>Таблицы, имеющиеся в базе данных:</p>";
echo "<ul>";
while ($row = mysql_fetch_row($result)) {
echo "<li>Таблица: " . $row[0] . "</li>";
}
echo "</ul>";

?>

Thanks.

Yakov  Jan 01, 2022 
PDF Page 184
Insert into code

In the Insert command, you are inserting the $twitter_handle, when you should be inserting the $twitter_url. This is the variable that is changed based on what the user had put in

Yochanon Raitzik  Jul 12, 2019 
Printed Page 205
Code section 6th line up from the bottom of the page

$position is an undefined variable in this script.

While the code produces the desired result, $position should be omitted for clarity.

Printed code:
substr($twitter_handle, $position + 1);

Proposed code:
substr($twitter_handle, 1);

Mark E.  Jan 22, 2017 
PDF Page 206
4th paragraph of section "Passing a User ID .."

The text 'Now, you could grab $_REQUEST['first_name'], and you?d get back ?Lance.?' seems to suggest that when you want to do a query for first name you only need to change the $_REQUEST['user_id'] into $_REQUEST['first_name']. However a few more changes are necessary to accomplish this:
- all occurrences of 'user_id' should be replace by 'first_name'
- a query for a string (e.g. Lance) requires that this string is enclosed with quotes. To achieve this you need:
$select_query = "SELECT * FROM users WHERE first_name = '" . $first_name ."'";

Theo  Jul 24, 2014 
Printed Page 210
12th line of <fieldset> code in bold print <input type="file"... />

From John Foster on July 27, 2013:
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.

My Suggestion:
The following line is missing the <br> tag at the end. It is the second line of new code in bold in the <fieldset> section.

<input type="file" name="user_pic" size="30" />

Should Read:
<input type="file" name="user_pic" size="30" /><br>

It is missing in my copy as well. 2nd Ed. Copyright 2013


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.

Anonymous  Jan 08, 2015 
PDF Page 211
First paragraph (code) 3rd line

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

and is missing a comma (,) after the variable insertion: '{$bio}'

Henry Gutierrez  Jun 15, 2015 
PDF Page 214
2nd paragraph

I believe this may probably be an issue on my end, but wanted to pose a question. Currently, I am entering the "header" line of code on this page exactly as printed in the book...to redirect the users to the show_user.php page...

header("Location: show_user.php?user_id=") . mysql_insert_id());
exit();

the above line of code is written as both the "create_user.php" and "show_user.php" files reside in the same relative directory path, however when submitting the form, my page continues to be directed to the "create_user.php" file... and I'm not certain why.

The one question I have... could this be because I am still utilizing my local web server on my computer vs having the files uploaded to a live web server, or could there be something else going on here?

So far to this point, all has been working as expected, AND the new entries ARE being logged to the database, I'm just displaying the show_user page.

If there is any further information I can provide, please let me know.

Thanks,
Will

Will Peters  Feb 02, 2015 
Printed Page 225
3rd paragraph, 2nd line

Typo - change "fine" to "find".

"Why couldn't they fine me?"
should read
"Why couldn't they find me?"

Mark E.  Jan 22, 2017 
PDF Page 231
First block of code - first html's paragraph, after php insertion

There is an <span> tag that should be not there, has not ending </span> tag
OR
it is misplaced, it should be before the <?php... ?> tags and a </span> tag is missing.

Henry Gutierrez  Jun 21, 2015 
PDF Page 234
Last block of code

You are missing the presentation of the message, either if the If statement is true or false, nothing is actually presented. A line of code like:

echo $error_message;

must be inserted after the last curly bracket (after the if statement) and before the end of the php code (?>)

Henry Gutierrez  Jun 21, 2015 
Printed Page 238
5

you aren't intimated (certainly not any more) by some techy details.

should probably be

you aren't intimidated (certainly not any more) by some techy details.

Miha  Nov 12, 2013 
Printed Page 243
Code example for connect.php beginning "if (!mysql_connect("

I had a devil of a time getting this code to work. My setup is:

Mac OS X 10.9.5
MySQL ver 14.14 distrib 5.6.10
PHP ver 5.4.30
Safari ver 7.1

The problem is: If mysql_connect() fails, the function itself throws an error onto the browser, which results in the following errors being displayed:

---- error messages ----
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /Users/xxx/Sites/phpMM/PHPmm2e_ch08_examples/04-Redirecting On Error/connect.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at /Users/xxx/Sites/phpMM/PHPmm2e_ch08_examples/04-Redirecting On Error/connect.php:6) in /Users/xxx/Sites/phpMM/PHPmm2e_ch08_examples/scripts/app_config.php on line 24
---- end error messages ----

FIX: Change the mysql_connect() function call to @mysql_connect(). The leading @ prevents the function from outputting the error message to the browser – and then the nicely formatted show_error.php can be used. See the third note on this documentation page:

http://php.net/manual/en/function.mysql-connect.php

Also – mysql_connect() is deprecated as of PHP 5.5.0, so the examples using it should probably be updated to use mysqli_connect() or PDO in the next edition of the text.

Dave Ross  Oct 22, 2014 
Printed Page 283
Middle of page $web_image_path statement

I am using only localhost with wamp. Previously HOST_WWW_ROOT was defined to be /home/bdmclaughlin...etc or in my case - /wamp/www. This results in entries in the database of user_image_path as /wamp/www/phpMM/uploads/.... .
$_SERVER['DOCUMENT_ROOT'] returns C:/wamp/www when we use this in str_replace it finds no match. I modified HOST_WWW_ROOT by adding C:.

Bill McLeod  Jan 30, 2014 
Printed Page 285
United States

/*
function get_web_path($file_system_path) {
return str_replace($_SERVER['DOCUMENT_ROOT'], '', $file_system_path);
}
*/
Would not work on live server. Using godaddy.com shared
change code to
function get_web_path($file_system_path) {
return str_replace("/var/chroot//home/content/14/8848514/html/", '/' , $file_system_path);
}
changed the $_SERVER['DOCUMENT_ROOT'] and added a forward slash to the empty string '/'.
on localhost just had to add the '/' to the empty string ''

function get_web_path($file_system_path) {
return str_replace($_SERVER['DOCUMENT_ROOT'], '/', $file_system_path);
}

Don Shipley  Sep 04, 2013 
PDF Page 312
top of page

The error can be found here in this code segment:

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


the $position variable that has been defined in all the previous codes seemed to have been deleted in the revision of show_user.php. It should be like this in order for it to work:


// Turn $twitter_handle into a URL
$position = strpos($twitter_handle, "@");
$twitter_url = "http://www.twitter.com/" . substr($twitter_handle, $position + 1);

haitiman  Aug 02, 2013 
ePub Page 327
Half way Point in Code Example setting variable $image_query

code example:

"$image_query = sprintf( "SELECT * FROM images WHERE image_id = %d " , $profile_pic_id ) ;

Should be $image_id a s the replacement for " %d "
NOT $profile_pic_id.

Mark Grover  Jan 21, 2015 
Printed Page 327
$image_query code

I keep getting an undefined variable when trying to run the code:

$image_id = $row['profile_pic_id'];

$image_query = sprintf("SELECT * FROM images WHERE image_id = %d",
$profile_pic_id);
$image_result = mysql_query($image_query);

I have double checked all of the code and also compared it to the missing cd example code. I do not know if it is an issue with the code itself or if I have a problem somewhere else.

AK Smith  Jul 24, 2015 
Printed Page 358
Second set of bold code

If anyone else is stumped as to why this code works:
<?php if (isset($msg)) { ?>
window.onload = function() {
alert("<?php echo $msg ?>");
}
<?php } ?>

save yourself some time and Google "PHP control structure" or "PHP control structure alternate syntax" or "PHP IF ENDIF" for an explanation.

I've never seen anything like it. It's a special way to break apart the opening and closing part of the IF control structure where you can conditionally execute JavaScript or HTML between the beginning "{" and ending "}".

It's strange, but extremely useful. I wish the author would've given the readers a head up as this syntax/method is not a well documented.

Mark E.  Jan 25, 2017 
Printed Page 362
United States

In first sentence the phrase " deleting a user" appears twice.

Spencer McLennan  Feb 17, 2014 
PDF Page 380
3rd

Using windows 7 with xamp php version 5.4.7
Ch11. Example 06-Integrate Utilities, Views, and Messages
Show_users.php ?script line 34
page_start("Current Users", $delete_user_script,
$_REQUEST['success_message'], $_REQUEST['error_message']);
Browser returns the notices:
Notice: Undefined index: success_message in C:\xampp\htdocs\phpMM2\ch11\06-Integrate Utilities, Views, and Messages\show_users.php on line 34

Notice: Undefined index: error_message in C:\xampp\htdocs\phpMM2\ch11\06-Integrate Utilities, Views, and Messages\show_users.php on line 34

I modified as below:
if (isset($_REQUEST['success_message']) || isset($_REQUEST['error_message'])) {
page_start("Current Users", $delete_user_script,
$_REQUEST['success_message'], $_REQUEST['error_message']);
} else {
page_start("Current Users", $delete_user_script);
}
It works without any notice
*******************************************************************************
Also, I modified the last part of the delete_user.php script example, FROM:
// Delete the user from the database
mysql_query($delete_query);

// Redirect to show_users to re-show users (without this deleted one)
$msg = "The user you specified has been deleted.";
header("Location: show_users.php?success_message={$msg}");
exit();
TO:
$result = mysql_query($delete_query);
if (!$result) {
// Redirect to notify show_users the error
$msg = "The user you specified has not been deleted.";
header("Location: show_users.php?error_message={$msg}");
exit();

} else {
// Redirect to show_users to re-show users (without this deleted one)
$msg = "The user you specified has been deleted.";
header("Location: show_users.php?success_message={$msg}");
exit();
}

Teo Maroulis  Oct 01, 2013 
ePub Page 394, 396
top of the page

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

This example is used in two pages and it will cause 2 errors to display.

These constants need to be in quotes as well. The correct way is as follows:

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

-------------------------------------------------------------------------------------
I added a ton of extra white space in this example to make it clear to read. Don't cut and paste this code. Re-Type it Please.

Mark Grover  Jan 22, 2015 
Printed Page 426
Last code paragraph under <html> tag

Page 427 has a closing </body> tag, but there isn't an opening <body> tag on page 426.

The code works as written, it's mostly a cleanliness issue.

Book code:
<html>
<div id="content">

Proposed change (add <body>) and rework indenting on both pages:
<html>
<body>
<div id="content">

Mark E.  Jan 27, 2017 
Printed Page 435

Using windows 7 with wamp php version 5.4.3
For signin.php You must change the $user_id = $_REQUEST['user_id']; in show_user.php to $_COOKIE['user_id']; to display without an error. However this will cause a problem with create_user.php. So to correct both Change the $_REQUEST['user_id']; to
if (isset($_COOKIE['user_id'])) {
$user_id = $_COOKIE['user_id'];
} else {
$user_id = $_REQUEST['user_id'];
}

in show_user.php. show_users.php will still work fine other than the error I am still having.

Don Shipley  Sep 15, 2013 
Printed Page 462-470
authorize_user function

The authorize_user function causes a redirect loop situation. I have tested this in several browsers. What happens is instead of authorizing the user, it returns the user to the previous page. I do not see where in the code this is happening. When the authorize_user function is turned off, I can reach the intended page, but then so can everyone else.

Allison Smith  Aug 18, 2015