Practical PHP and MySQL Website Databases A Simplified Approach - Adrian W. West.pdf

(15304 KB) Pobierz
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Author �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xix
About the Technical Reviewer �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xxi
Acknowledgments �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xxiii
Introduction �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xxv
■
Chapter 1: Create and Test a MySQL Database and Table�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½1
■
Chapter 2: Create Web Pages That Interact with Users �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½25
■
Chapter 3: Login/Logout for Members and an Administrator �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½61
■
Chapter 4: Display Membership Tables for the Administrator�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½93
■
Chapter 5: Register Addresses and Phone Numbers �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½125
■
Chapter 6: The Finishing Touches �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½157
■
Chapter 7: Migrating to a Host and Backing Up Your Web Site Database �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½187
■
Chapter 8: Creating a Product Catalog �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½223
■
Chapter 9: Adding Multiple Tables and Other Enhancements�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½259
■
Chapter 10: Creating a Message Board �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½295
■
Chapter 11: E-Commerce: A Brief Introduction �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½335
■
Chapter 12: Troubleshooting Your Database-Driven Web Site �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½379
■
Appendix �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½387
Index �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½407
v
Introduction
The Teaching Method
I am a web site designer rather than a programmer. My choice of a book is based on how much practical application
it contains, not on how much a book concentrates on the syntax of a language as an end in itself. This book follows
my preference; therefore,
Practical PHP and MySQL Web Site Databases - A Simplified Approach
uses a different way
of teaching web site database design than the majority of manuals. The usual layout starts with several lessons on
PHP followed by snippets of command-line code, and it may eventually conclude with a project or two. This book
abandons that approach. The primary focus is on fully worked, practical MySQL database projects built into
real-world web pages.
In this book, practical databases and interactive web pages are presented as early as possible; in fact, you will
create a database and a table in the first chapter. In the second chapter, you will embed a database into an interactive
(dynamic) web page and test it. Each subsequent chapter will introduce you to increasingly sophisticated and useful
database-driven web site pages.
To a busy web designer who is unfamiliar with PHP and databases, the requirements in order of importance are
as follows:
•
•
•
•
How to embed PHP and interactive databases into real-world web pages. This is the primary
theme throughout the book.
How to create a free environment for testing database-driven web pages.
How to create a user-friendly interface so that an administrator with minimum computer skills
can monitor the database.
To understand how PHP, HTML, and MySQL work together to create and maintain a database
and its data.
Instead of presenting PHP, SQL, and MYSQL as completely separate topics, these are explained in context as the
projects unfold. However, when you eventually become proficient in these languages, a quick PHP/MySQL reference
would be helpful; therefore, you will find this in the Appendix.
Because databases can only be viewed and tested on a server, the first part of Chapter 1 has instructions for using
a free server that can be downloaded and installed on the reader’s computer. This ensures that readers will have a safe
development platform for learning and testing as they explore the book’s practical projects.
A study of the theory and syntax can deter learners and prolong the time until they get their hands on a practical
application. The history and development of the car and a study of the internal combustion engine will not help a
would-be driver. However, jumping into a car and driving it will produce quicker results, and learners are enthused
when they achieve something. This book jumps into the database driving seat right from the beginning. Essential PHP
and MySQL techniques are presented in context within each tutorial, where they are most relevant.
Some database text books advocate using a framework; they suggest that this facilitates the development of a
database-driven web site. I find frameworks utterly confusing, even though I have experience programming databases
using raw code. If you are a beginner, I suggest you steer clear of frameworks until you have gained some more
experience and understand the fundamentals of how a database-driven website works.
xxv
■
IntroduCtIon
Who Is This Book For?
The book assumes that the reader is thoroughly familiar with HTML and CSS. However, concerning MySQL, PHP,
and phpMyAdmin, the book starts from an absolute beginner’s point of view. As the chapters unfold, they progress
towards intermediate level. Because command-line programming would not be welcomed by the modern generation
of readers, the book concentrates on mouse-operated Graphical User Interfaces (GUIs) and PHP files for creating and
managing databases.
You do not need to acquire an extensive knowledge of PHP to create interactive databases. I introduce all the PHP
you will need in the appropriate place within each project. Each piece of PHP code is explained fully in plain English.
The step-by-step, fully-worked examples will show you what MySQL and PHP can do and how to do it.
Practical PHP
and MySQL Web Site Databases - A Simplified Approach
is for web designers who wish to begin developing
database-driven web sites. Like the author, they may have struggled with the current manuals and despaired. They
may also have been frustrated by the limitations of paint-by-numbers content management systems such as Joomla
and Wordpress.
With this in mind,
Practical PHP and MySQL Web Site Databases - A Simplified Approach
uses a highly
motivational, step-by-step approach. The author recognizes fully that a sense of achievement encourages the reader to
look forward eagerly to the next step. For readers who have little or no knowledge of PHP, the book will teach enough
PHP to complete all the projects in the book. Web developers who are ready to move beyond the MySQL basics, or
who have not kept up to date with their MySQL and PHP, will also benefit from
Practical PHP and MySQL Web Site
Databases - A Simplified Approach.
College and university IT teachers will find that the book provides an excellent set text; the projects can form a
basis for students to adapt for their course work.
The “Quick and Easy-to-Learn” Myth
Manuals frequently state that PHP and MySQL databases are easily and quickly learned. This discourages beginners,
because when they are confronted with the inevitable difficulties (and error messages), they begin to think that they
will never grasp even the basic principles.
Beginners should not be discouraged if they remember the following fact: authors claiming that PHP and MySQL
are easily and quickly learned are not being deceptive; they have probably been using PHP and MySQL for more than
a decade and have forgotten the difficulties they encountered when they first began.
If you accept that some time and effort is required to learn PHP and MySQL, then as time passes, it will become
increasingly apparent that you are learning something very worthwhile. The task will become progressively easier,
so have patience and persevere. You will then begin to enjoy mastering this valuable new discipline.
The Origin of This Book
I was asked to enhance one of my client’s web sites by adding a membership database and a members’ registration
form. Although I have designed, developed, and maintained web sites for many years, I had no knowledge of MySQL
databases. I bought and borrowed a boatload of books and searched the Internet for tutorials. I was very disappointed
with the majority of the books.
Most of the MySQL manuals tended to demonstrate the author’s deep and extensive knowledge of PHP and
MySQL instead of teaching how to embed MySQL databases into web pages. In contrast , this book uses fully worked
examples to demonstrate how to integrate databases into a web site.
PHP/MySQL manuals can have up to 800 pages, which would deter any beginner. I once bought such a manual.
It contained hardly any practical worked examples. This meant that I could only use the book to stand on when
changing a light bulb. (The manual was almost 2 inches thick.)
xxvi
Zgłoś jeśli naruszono regulamin