Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 30th, 2010, 03:46 PM
Authorized User
Points: 374, Level: 6
Points: 374, Level: 6 Points: 374, Level: 6 Points: 374, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: San Jose, Californina
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default Chap 8, Shopping Cart, issues, Ajax, missing file - checkout.php

Chapter 8 - Shopping Cart

There are two main parts to this
chapter: 1) Entering the inventory data
into the database 2) the shopping cart.

PART 1

Entering the inventory data into the database.

This is actually in the second part of the
chapter, pages 217-234. I like to do this first
so my database will be populated when I
do the shopping cart part.

ISSUE # 1 - Browsers

Use Internet Explorer for this part.
Firefox will not work.

This was first discovered in the post Chapter 8, shop

All this part of the code does is enter
inventory data into the database. It
will only be used by administrators of
the web site, not visitors (customers), so
I guess you could get away with imposing a
requirement that your web site administrators
use IE only. Still, it would
be much better if it could be done from any browser.


ISSUE # 2 inventory_process.php, syntax error in query statement

This issue was first addressed in the post Shopping Cart Code incomplete

In inventory_process.php, near line 127, in the section under

PHP Code:
else if (isset($_GET['save_item'])) 
there is a syntax error in the $query statement

PHP Code:
.....
   
'( "%s", %02f, "%s" %d)',
..... 
The format description is not
correct. It is missing a format descriptor for
the ITEM_DESCRIPTION field,
and it is missing a comma between the last two fields.

it should be

PHP Code:
'( "%s", "%s", %02f, "%s", %d)'
The line should look like this (Mine is slightly different, I don't
use the Wrox prefix).

PHP Code:
 $query sprintf('INSERT INTO SHOP_INVENTORY (ITEM_NAME, ' .
            
'ITEM_DESCRIPTION, PRICE, ITEM_IMAGE, CATEGORY_ID) VALUES ' .
            
'( "%s", "%s", %02f, "%s", %d)',
            
mysql_real_escape_string($_POST['name'], $GLOBALS['DB']),
            
mysql_real_escape_string($_POST['description'], $GLOBALS['DB']),
            
$_POST['price'],
            
mysql_real_escape_string($_POST['image'], $GLOBALS['DB']),
            
$_POST['cat_id']); 
The book is also not correct, but it is not correct
in a different way.
The book does not have the format specifier
for the ITEM_IMAGE. It also does not have the
value for the ITEM_IMAGE. It appears ITEM_IMAGE
was left out altogether.
This would be on page 223, about lines 7-15,
which is the $query statement.


ISSUE # 3 - inventory_process.php, syntax error in another query statement

In that same section, near line 150, right below

PHP Code:
// update an existing record 
the format specifier for price is not correct.

PHP Code:
'PRICE = %02d, ITEM_IMAGE = "%s", CATEGORY_ID = %d ' 
It should be %02f, not %02d

PHP Code:
'PRICE = %02f, ITEM_IMAGE = "%s", CATEGORY_ID = %d ' 
ISSUE # 4 - debugging, be careful with print statements to the browser

When debugging and troubleshooting be careful to avoid
making print statements to the browser in file
inventory_process.php. inventory_process.php is processing the AJAX request,
and putting any print statements in this file can cause
problems such as leaving fields blank that should be filled,
getting wrong entries in text fields, and other things.
It is best to write your debugging statement to an
error log file instead.


ISSUE # 5 - security around inventory.hmtl

You need to make sure people cannot get to
inventory.html from typing it in on the browser.
You could implement some security checks around
inventory.html

*****

After I did these things, the inventory part worked for me.


PART 2

The shopping cart.

This part is the first part of the chapter and
goes from page 195 to page 217. I do this part
after I have completed part 1 above, that way
I have a populated database to work with.


ISSUE # 1 - Browsers

For this shopping cart part, it seems to work with
both IE and Firefox.

ISSUE # 2 - ShoppingCart.php

ShoppingCart.php, in the download code, about line 21,
should be "break", not "brake".

PHP Code:
case 'contents':
           return 
$this->items;
           break; 
This is not correct in the book either, page 199, line 2

ISSUE # 3 - closing <form> and <select> in cart.php

In another post Shopping Cart Code incomplete depishedesign discovered
that <form> and <select> are not closed. That was a good find. Now, I actually ran the code with the tags not
closed and the code actually ran. Sometimes HTML lets you get
away with things like that, however, it is best to close
those tags.


ISSUE # 4 - Missing file - checkout.php

cart.php refers a file - checkout.php.
This file is missing. It is missing in the download code.
It is missing in the book. It is not described in
the book.

Here is the reference to it in cart.php, about line 158

PHP Code:
// display link to checkout
  
echo '<p><a href="checkout.php">';
  echo 
'<img src="img/checkout.gif" alt="Proceed to Checkout"/></a></p>'
At the top of page 204, in the text the author says
"Depending on your checkout procedure...". This seems
to imply it is up to us to implement our own
checkout procedures.

I guess you could temporarily stub it out by creating
your own checkout.php that just puts
out a message or something.

*****
Other than the missing checkout.php file, the
shopping cart was working for me.

*********************

MY CONFIGURATION

I used the download code for this which
I downloaded in May 2010

browsers:

Internet Explorer 8.0
Firefox 3.0.19

> php -version
PHP 5.2.12 (cli) (built: Mar 18 2010 23:47:09)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
>

Unix:
FreeBSD 4.10-RELEASE FreeBSD 4.10-RELEASE #10: Mon Jul 30 13:42:38 MDT 2007 i386

MySQL server - 4.1.22

******************************

DUPLICATE FILE NAME ISSUE

Some of the file names used in chapter 8 are the
same file names as existing files from previous chapters.
This can result in some existing files being overwritten.

Here is a list of the files I noticed.

The js/ajax.js

This file was used in chapter 7.
The content is the same so no damage is done.

css/styles.css
This is different than the styles file used in chap3
and chap1.
I have named mine styles8.css

lib/common.php - unchanged
lib/db.php - unchanged
Reply With Quote
  #2 (permalink)  
Old November 22nd, 2012, 05:23 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding items to cart

Hi,
When I load the product page, there is no button appearing to add the item to the cart.
Is there a problem with the code?
Thanks for your help,
Ben
Reply With Quote
  #3 (permalink)  
Old November 22nd, 2012, 01:26 PM
Authorized User
Points: 374, Level: 6
Points: 374, Level: 6 Points: 374, Level: 6 Points: 374, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: San Jose, Californina
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default

Hi Benster,

This is working for me.

The code for this should be in the
file shop.php around line 60. Here is
the code I had.
Code:
if (!$cart->qtyItem($row['ITEM_ID']))   {
    echo '<a href="cart.php?add&item=' . $row['ITEM_ID'] . '">';
    echo '<img src="img/cartadd.gif" alt="Add to Cart"/></a>';
} else {
    echo '<a href="cart.php?remove&item=' . $row['ITEM_ID'] . '">';
    echo '<img src="img/cartremove.gif" alt="Remove from Cart"/></a>';
}
Does everything else on the page show up like it should?
It should look something like figure 8-4 on page 213.
If so, you should reach this if statement, but let us
make sure.

Try putting an echo "hello"; right before the if
statement. If this doesn't show up, then somehow
your HTML table is messed up and not displaying the text in
the correct location, or not displaying it at all.

If it does show up, then troubleshoot the if block.
Change if statement to
Code:
if (1)
and verify that the
add button or alt text shows up. Change to
Code:
if(0)
to check that the remove button shows up.

If it is getting into the if block, are you sure you
have the img/cartadd.gif file? If it can't find the
image it should put up the alt text which is
"Add to Cart". Do you see that?

Be sure to check the error log file too.

You asked if there is a problem with the code.
The problems I have found in the code are all stated
in the first post on this thread. I have not
found any additional problems since that time.

I am on now on Firefox 16.0.2

I hope this helps.
Reply With Quote
  #4 (permalink)  
Old November 22nd, 2012, 04:10 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks for this.

I used Dreamweaver and just checked live view and the buttons appeared.

Went to check in Safari Browser and the buttons weren't there at all - not even the alt description. But the "view cart" button is there.

Loaded page in Explorer and Chrome- and the buttons are there!

So it would appear there is nothing wrong with the code afterall except there does appear to be browser compatability issues?

Why does it not work in Safari?

Last edited by benster; November 22nd, 2012 at 04:12 PM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 7 - check_effect.php file drgnhiker BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 March 29th, 2010 04:50 PM
Free php shopping cart heerajee Pro PHP 1 April 20th, 2006 02:32 PM
http_client.php shopping cart error boetheus Beginning PHP 0 November 21st, 2004 10:22 AM
shopping cart in php isheikh PHP How-To 1 October 22nd, 2004 08:17 PM
PHP Source Code for Shopping cart haribabu PHP How-To 0 January 27th, 2004 01:10 AM



All times are GMT -4. The time now is 10:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.