(Ebook) Learning PHP, MySQL, and JavaScript by Robin Nixon ISBN 9780596157135, 0596157134instant download
(Ebook) Learning PHP, MySQL, and JavaScript by Robin Nixon ISBN 9780596157135, 0596157134instant download
https://ebooknice.com/product/learning-php-mysql-and-
javascript-1216936
https://ebooknice.com/product/learning-php-mysql-javascript-4761774
https://ebooknice.com/product/learning-php-mysql-javascript-and-css-2618790
https://ebooknice.com/product/learning-php-mysql-javascript-early-
release-24129590
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
(Ebook) Learning PHP, MySQL & JavaScript - With jQuery, CSS &
HTML5 by Robin Nixon ISBN 9781491978917, 1491978910
https://ebooknice.com/product/learning-php-mysql-javascript-with-jquery-
css-html5-7294746
https://ebooknice.com/product/learning-php-mysql-javascript-6th-
edition-23267530
https://ebooknice.com/product/learning-php-mysql-javascript-7th-
edition-54117148
(Ebook) Learning PHP, MySQL & JavaScript: With jQuery, CSS &
HTML5 (Early Release 5th) by Robin Nixon ISBN 9781491978917,
1491978910
https://ebooknice.com/product/learning-php-mysql-javascript-with-jquery-
css-html5-early-release-5th-6855160
https://ebooknice.com/product/learning-php-mysql-javascript-css-
html5-third-edition-a-step-by-step-guide-to-creating-dynamic-
websites-4724548
Learning PHP, MySQL, and
JavaScript
Robin Nixon
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.
Printing History:
July 2009: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Learning PHP, MySQL, and JavaScript, the image of sugar gliders, and related trade
dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
TM
ISBN: 978-0-596-15713-5
[M]
1246467361
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
iii
3. Introduction to PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Incorporating PHP Within HTML 33
Calling the PHP Parser 34
This Book’s Examples 35
The Structure of PHP 36
Using Comments 36
Basic Syntax 37
Understanding Variables 38
Operators 42
Variable Assignment 45
Multiple-Line Commands 47
Variable Typing 49
Constants 50
The Difference Between the echo and print Commands 51
Functions 52
Variable Scope 53
Test Your Knowledge: Questions 58
iv | Table of Contents
5. PHP Functions and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
PHP Functions 90
Defining a Function 91
Returning a Value 92
Returning an Array 93
Passing by Reference 94
Returning Global Variables 95
Recap of Variable Scope 96
Including and Requiring Files 96
The include Statement 96
Using include_once 97
Using require and require_once 97
PHP Version Compatibility 98
PHP Objects 98
Terminology 99
Declaring a Class 100
Creating an Object 101
Accessing Objects 101
Constructors 104
Writing Methods 105
Declaring Properties 106
Declaring Constants 107
Property and Method Scope in PHP 5 107
Inheritance 109
Test Your Knowledge: Questions 113
Table of Contents | v
Test Your Knowledge: Questions 128
vi | Table of Contents
Using Logical Operators 194
MySQL Functions 194
Accessing MySQL via phpMyAdmin 195
Windows Users 195
Mac OS X Users 195
Linux Users 195
Using phpMyAdmin 197
Test Your Knowledge: Questions 198
Table of Contents | ix
15. Expressions and Control Flow in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Expressions 319
Literals and Variables 320
Operators 321
Operator Precedence 321
Associativity 322
Relational Operators 323
The with Statement 325
Using onError 326
Using try...catch 327
Conditionals 328
The if Statement 328
The switch Statement 329
The ? Operator 331
Looping 331
while Loops 331
do...while Loops 332
for Loops 332
Breaking Out of a Loop 333
The continue Statement 334
Explicit Casting 334
Test Your Knowledge: Questions 335
x | Table of Contents
The validate.html Document (Part Two) 358
Regular Expressions 361
Matching Through Metacharacters 361
Fuzzy Character Matching 362
Grouping Through Parentheses 363
Character Classes 363
Indicating a Range 364
Negation 364
Some More Complicated Examples 364
Summary of Metacharacters 367
General Modifiers 369
Using Regular Expressions in JavaScript 369
Using Regular Expressions in PHP 369
Redisplaying a Form After PHP Validation 370
Test Your Knowledge: Questions 375
Table of Contents | xi
Checking for Username Availability 412
rnsignup.php (YUI version) 415
rncheckuser.php 417
rnlogin.php 417
rnprofile.php 419
Adding the “About Me” Text 420
Adding a Profile Image 420
Processing the Image 420
Displaying the Current Profile 421
rnmembers.php 424
Viewing a User’s Profile 424
Adding and Dropping Friends 424
Listing All Members 424
rnfriends.php 427
rnmessages.php 430
rnlogout.php 432
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
The combination of PHP and MySQL is the most convenient approach to dynamic,
database-driven web design, holding its own in the face of challenges from integrated
frameworks—such as Ruby on Rails—that are harder to learn. Due to its open source
roots (unlike the competing Microsoft .NET framework), it is free to implement and is
therefore an extremely popular option for web development.
Any would-be developer on a Unix/Linux or even a Windows/Apache platform will
need to master these technologies. At the same time, the JavaScript is important, as it
provides the hidden communication with the web server to create seamless interfaces.
Audience
This book is for people who wish to learn how to create effective and dynamic websites.
This may include webmasters or graphic designers who are already creating static web-
sites but wish to take their skills to the next level as well as high school and college
students, recent graduates, and self-taught individuals.
In fact, anyone ready to learn the fundamentals behind the Web 2.0 technology known
as Ajax will obtain a thorough grounding in all three of the core technologies: PHP,
MySQL, and JavaScript.
xiii
Organization of This Book
The chapters in this book are written in a specific order, first introducing all three of
the core technologies it covers and then walking you through their installation on a
web development server, so that you will be ready to work through the examples.
In the following section, you will gain a grounding in the PHP programming language,
covering the basics of syntax, arrays, functions, and object-oriented programming.
Then, with PHP under your belt, you will move on to an introduction to the MySQL
database system, where you will learn everything from how MySQL databases are
structured up to generating complex queries.
After that, you will learn how you can combine PHP and MySQL to start creating your
own dynamic web pages by integrating forms and other HTML features. You will then
spend some time looking at ways to speed up your web development using Smarty
templates.
In the next three chapters, you will get down to the nitty-gritty practical aspects of PHP
and MySQL development by learning a variety of useful functions and how to manage
cookies and sessions, as well as how to maintain a high level of security.
In the following four chapters, you will gain a thorough grounding in JavaScript, from
simple functions and event handling to accessing the Document Object Model and in-
browser validation and error handling.
With an understanding of all three of these core technologies, you will then learn how
to make behind-the-scenes Ajax calls and turn your websites into highly dynamic
environments.
Finally, you’ll put together everything you’ve learned in a complete set of PHP programs
that together constitute a fully working social networking website.
Along the way, you’ll also find plenty of pointers and advice on good programming
practices and tips that could help you find and solve hard-to-detect programming er-
rors. There are also plenty of links to websites containing further details on the topics
covered.
Supporting Books
Once you have learned to develop using PHP, MySQL, and JavaScript you will be ready
to take your skills to the next level using the following reference books:
• Dynamic HTML: The Definitive Reference by Danny Goodman (O’Reilly)
• PHP in a Nutshell by Paul Hudson (O’Reilly)
• MySQL in a Nutshell by Russell Dyer (O’Reilly)
• JavaScript: The Definitive Guide by David Flanagan (O’Reilly)
xiv | Preface
Conventions Used in This Book
The following typographical conventions are used in this book:
Plain text
Indicates menu titles, options, and buttons.
Italic
Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames,
directories, and Unix utilities.
Constant width
Indicates command-line options, variables and other code elements, HTML tags,
macros, the contents of files, and the output from commands.
Constant width bold
Shows commands or other text that should be typed literally by the user; also
occasionally used for emphasis.
Constant width italic
Shows text that should be replaced with user-supplied values.
Preface | xv
We’d Like to Hear from You
Every example in this book has been tested on various platforms, but occasionally you
may encounter problems; for example, if you have a nonstandard installation or a dif-
ferent version of PHP, and so on. The information in this book has also been verified
at each step of the production process. However, mistakes and oversights can occur
and we will gratefully receive details of any you find, as well as any suggestions you
would like to make for future editions. You can contact the author and editors at:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://www.oreilly.com/catalog/9780596157135
There is also a companion website to this book available online at:
http://lpmj.net
where you can see all the examples with color-highlighted syntax. To comment or ask
technical questions about this book, send email to the following address, mentioning
its ISBN number (9780596157135):
bookquestions@oreilly.com
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our website at:
http://www.oreilly.com
xvi | Preface
Acknowledgments
A huge thank you goes to my editor, Andy Oram, and all the folks at O’Reilly who
worked so hard on this book, and without whom it could never have been written.
In particular I must thank my technical reviewers, Derek DeHart, Christoph Dorn,
Tomislav Dugandzic, Becka Morgan, Harry Nixon, Alan Solis, and Demian Turner, for
their help in ensuring the accuracy of this book.
I wish to also thank my wife, Julie, for her constant encouragement, and also Rachel,
Hannah, Laura, Matthew, Harry, and Naomi, wonderful children who all helped with
this project—each in their own way.
Preface | xvii
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Fairview Boys
and Their Rivals; or, Bob Bouncer's Schooldays
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
OR
BY
FREDERICK GORDON
AUTHOR OF “THE YOUNG CRUSOES OF PINE ISLAND,”
“SAMMY BROWN’S TREASURE HUNT,” ETC.
ILLUSTRATED
CHARLES E. GRAHAM & CO.
NEWARK, N. J. — NEW YORK
CHAPTER PAGE
I. Three Chums 7
II. The First Day at School 18
III. The Lost Letters 30
IV. Something of a Mystery 38
V. The Big Bonfire 50
VI. Bombarded 56
VII. The Spelling Contest 64
VIII. The Mad Bull 71
IX. The Nutting Party 79
X. “The Day of Their Lives” 85
XI. Robbery 93
XII. Bob Bouncer’s Clew 100
XIII. An Exciting Hour 108
XIV. Fire 115
XV. The Capture—Conclusion 124
Fairview Boys and Their Rivals
OR
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com