43
622
Chapter 27 Building a Shopping Cart
You even get a different submit button.In fact,for the edit form,you get two—one to
update the book and one to delete it.These buttons call the scripts
edit_book.php
and
delete_book.php
,which update the database accordingly.
The category versions of these scripts work in much the same way,except for one
thing.When an administrator tries to delete a category,it will not be deleted if any
books are still in it.(This is checked with a database query.) This approach prevents any
problems you might get with deletion anomalies.We discussed these anomalies in
Chapter 8,“Designing Your Web Database.”In this case,if a category that still had books
in it was deleted,these books would become orphans.You wouldn’t know what category
they were in,and you would have no way of navigating to them!
That’s the overview of the administration interface. For more details,refer to the
code; it’s all on the CD-ROM.
Extending the Project
If you followed along with this project,you have built a fairly simple shopping cart sys-
tem.There are many additions and enhancements you could make:
n
In a real online store,you would need to build some kind of order tracking and
fulfillment system.At the moment,you have no way of seeing the orders that have
been placed.
n
Customers want to be able to check the progress of their orders without having to
contact you.We feel that it is important that a customer does not have to log in to
browse.However, providing existing customers a way to authenticate themselves
enables them to see past orders and enables you to tie behaviors together into a
profile.
n
At present,the images for books have to be transferred via FTP to the image
directory and given the correct name.You could add file upload to the book inser-
tion page to make this process easier.
n
You could add user login,personalization, and book recommendations;online
reviews; affiliate programs;stock level checking; and so on.The possibilities are
endless.
Using an Existing System
If you want to get a highly featured shopping cart up and running quickly,you might
want to try using an existing shopping cart system.One well known open source cart
implemented in PHP is FishCartSQL,available from
http://www.fishcart.org/