Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi,

 

I believe I found 2 mistakes in the (downloadable example codes)

 

The first is in the MySQL file in the table orders, the MySQL file states: 

 

CREATE TABLE `orders` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`users_id` INT UNSIGNED NOT NULL,
`transaction_id` VARCHAR(45) NOT NULL,
`payment_status` VARCHAR(45) NOT NULL,
`payment_amount` INT UNSIGNED NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `date_created` (`date_created` ASC),
INDEX `transaction_id` (`transaction_id` ASC),
CONSTRAINT `fk_orders_users1`
FOREIGN KEY (`id`)
REFERENCES `users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
The constraint states the foreign key is 'id' and references to table 'users' id, however the id in table orders is auto incremented. Should it not be FOREIGN KEY (users_id) with REFERENCES `users` (`id`)??

The second is on page 173 (Chapter Creating the IPN script)
The query states: $q = "INSERT INTO orders (user_id, transaction_id, payment_status, payment_amount) VALUES ($uid, '$txn_id', '$status', $amount)";

However I believe user_id should be users_id
 
I am probably be wrong because even with these changes I just cant get the IPN script to work, i found a alternative script that does work though. 
 
 
Link to comment
Share on other sites

No problem, thx for the book and available example codes.

 

Found another one :)

 

In the page.php file for recording the history the example files state:

$q = "INSERT INTO history (user_id, type, page_id) VALUES ({$_SESSION['user_id']}, 'page', $page_id)";
$r = mysqli_query($dbc, $q);
 
the query should state item_id instead of page_id, in the book this is written correct.
 
 
In the favorites.php example files it states:
// Include the header file:
$page_title = 'Your Favorite Pages';
include('./includes/header.html');
 
echo '<h3>Your Favorite Pages</h3>';
 
// Require the database connection:
require(MYSQL);

the require(MYSQL); should be placed before the header.html part because the header.html file makes a MySQL query for categories and the require mysql file is not in that file.
 
 

page 394 updating register.php and page 395 updating add_page.php with prepared statement

mysqli_stmt_close(); should be mysqli_stmt_close($stmt);

Link to comment
Share on other sites

  • 7 months later...

THANK YOU joost!  I couldn't get the 'favorites' link to display correctly.  The error was showing in the sidebar as an error with header.html but it was because of that misplaced link in the favorites.php!!  I relocated the MYSQL include statement and now it displays correctly!

Link to comment
Share on other sites

  • 7 months later...
The second is on page 173 (Chapter Creating the IPN script)
The query states: $q = "INSERT INTO orders (user_id, transaction_id, payment_status, payment_amount) VALUES ($uid, '$txn_id', '$status', $amount)";

 

However I believe user_id should be users_id

 

This error has not been added to the ERRATA page for this book. I looked for it there first, then decided to check the forums and found it here.

Link to comment
Share on other sites

On page 172, number 9, I had to change 'payment_status', 'receiver_email' and 'mc_gross' from === to == because the IPN would not work.

 

        // Check for the right values:
        if ( isset($_POST['payment_status'])
         && ($_POST['payment_status'] == 'Completed')
         && ($_POST['receiver_email'] == 'treasurer@nmsc.org')
         && ($_POST['mc_gross'] == 40.00)
         && ($_POST['mc_currency']  === 'USD')
         && (!empty($_POST['txn_id']))

 

Because ipn.php is not a page you can test normally (like, with echo statements), how I troubleshooted this, was I created a text file on the server called 'ipn_troubleshooter.txt" and where I would normally put echo statements to find out where the code is broken, I instead made fwrite calls to the text file. If the file didn;t get updated, I knew the code was broken at the point I called the fwrite. In this case it was "&& ($_POST['payment_status'] === 'Completed')" that was broken, so I changed it to == and it worked, then I made may way through the others, fixing only the ones that were broken.

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...