PHP For Teens 1st Edition Maneesh Sethi instant download
PHP For Teens 1st Edition Maneesh Sethi instant download
https://ebookname.com/product/php-for-teens-1st-edition-maneesh-
sethi/
https://ebookname.com/product/game-programming-for-teens-second-
edition-maneesh-sethi/
https://ebookname.com/product/torque-for-teens-1st-edition-mike-
duggan/
https://ebookname.com/product/rpg-maker-for-teens-1st-edition-
michael-duggan/
https://ebookname.com/product/educating-pupils-with-autistic-
spectrum-disorders-a-practical-guide-1st-edition-dr-martin-
hanbury/
Analysis of Panel Data 3rd Edition Cheng Hsiao
https://ebookname.com/product/analysis-of-panel-data-3rd-edition-
cheng-hsiao/
https://ebookname.com/product/cooking-with-coconut-flour-bruce-
fife/
https://ebookname.com/product/ipv6-essentials-1st-edition-silvia-
hagen/
https://ebookname.com/product/decentring-the-avant-garde-1st-
edition-per-backstrom/
https://ebookname.com/product/light-scattering-by-particles-in-
water-theoretical-and-experimental-foundations-1st-edition-
miroslaw-jonasz/
Drilling for Gold How Corporations Can Successfully
Market to Small Businesses 1st Edition John Warrillow
https://ebookname.com/product/drilling-for-gold-how-corporations-
can-successfully-market-to-small-businesses-1st-edition-john-
warrillow/
PHP for
Teens
Maneesh Sethi
ß 2006 Thomson Course Technology, a division of Thomson Learning Publisher and General Manager,
Inc. All rights reserved. No part of this book may be reproduced or Thomson Course Technology PTR:
transmitted in any form or by any means, electronic or mechanical, Stacy L. Hiquet
including photocopying, recording, or by any information storage or
retrieval system without written permission from Thomson Course Associate Director of Marketing:
Technology PTR, except for the inclusion of brief quotations in a Sarah O’Donnell
review.
Manager of Editorial Services:
The Thomson Course Technology PTR logo and related trade dress Heather Talbot
are trademarks of Thomson Course Technology, a division of
Thomson Learning Inc., and may not be used without written per- Marketing Manager:
mission. This product includes PHP software, freely available from Heather Hurley
http://www.php.net/software/.
Senior Acquisitions Editor:
All other trademarks are the property of their respective owners. Emi Smith
Important: Thomson Course Technology PTR cannot provide software Project Editor:
support. Please contact the appropriate software manufacturer’s Tonya Cupp
technical support line or Web site for assistance.
Technical Reviewers:
Thomson Course Technology PTR and the author have attempted Andy Harris, Christopher McCulloh
throughout this book to distinguish proprietary trademarks from
descriptive terms by following the capitalization style used by the Teen Reviewer:
manufacturer. Justin Windler
Information contained in this book has been obtained by Thomson
PTR Editorial Services Coordinator:
Course Technology PTR from sources believed to be reliable. However,
Elizabeth Furbish
because of the possibility of human or mechanical error by our sources,
Thomson Course Technology PTR, or others, the Publisher does not Interior Layout Tech:
guarantee the accuracy, adequacy, or completeness of any information Interactive Composition Corp.
and is not responsible for any errors or omissions or the results
obtained from use of such information. Readers should be particularly Cover Designer:
aware of the fact that the Internet is an ever-changing entity. Some facts Mike Tanamachi
may have changed since this book went to press.
CD-ROM Producer:
Educational facilities, companies, and organizations interested in Brandon Penticuff
multiple copies or licensing of this book should contact the Publisher
for quantity discount information. Training manuals, CD-ROMs, and Indexer:
portions of this book are also available individually or can be tailored Sharon Shock
for specific needs.
Proofreader:
ISBN-10: 1-59863-139-X
Megan Wade
ISBN-13: 978-1-59863-139-5
eISBN-10:1-59863-140-3
Library of Congress Catalog Card Number: 2006920364
Printed in the United States of America
06 07 08 09 10 PH 10 9 8 7 6 5 4 3 2
Acknowledgments
There are a lot of people to thank for this work. Really, to everyone who played a
part during the writing of this book, thank you so much.
First of all, I want to thank my parents, Neelam and Prab Sethi. My brother was a
big help to me with surviving this year; thanks Ramit. My sisters Nagina and
Rachi are awesome, and I love you both so much.
Thanks to Emi Smith, my acquisitions editor, Tonya Cupp, my copy editor, and
Andy Harris and Christopher McCullough, my tech editors. Everyone else at
Course PTR—you guys are great.
Lastly, my friends: Thanks a lot, you guys. I want to give special thanks to my
college roommates during the writing of this book, Nate Foorman and Arthur
Kaneko (Theo Polan too, sort of). Also, many thanks to David Weekly for his
help programming and all sorts of computer stuff.
To everyone else, and Lauren Choi: Thanks so much for your help! Keep in
touch!
iii
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
iv
Contents v
Form Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Submit Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Adding PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
do . . . while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
break and continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Introduction
If you are holding this in your hand, you probably have some knowledge about
the web—either that or someone asked you to buy this book for them. Whatever
the case, you have found a gold mine! From this book you learn the secrets to
dynamic web sites with PHP.
What is dynamic content? Making a site change based on given information
(hence the word dynamic). Perhaps you want to make a site where you can have
several members who all store their own favorite links. Well, with PHP, you can
make your site offer dynamically different links to each user, maybe based on
recommendations or previous links. PHP gives you total control.
ix
x Introduction
What is the minimum knowledge you need to succeed here? You should be able
operate a computer well. If you can use your PC or Apple without any major
difficulties, you will probably do fine in this book. This book is paced for a
beginner, and topics work on a PC, Mac, or Linux computer. I have included
information on how to install the software for PCs and Macs, but you can find
Linux instructions on www.php.net.
If you ever have any problems with any of this, feel free to email me at
maneesh@maneeshsethi.com.
Welcome to PHP
Hey, welcome to PHP For Teens. I’m really glad you picked up this book, and I
want to let you know that you are in for a great ride. PHP, while easy to learn, is
also an incredibly powerful and useful language, and this book will teach you
everything you need to know to make some seriously dynamic web sites.
So what does PHP actually mean? PHP itself stands for PHP: Hypertext
processor—seriously. Seems kind of crazy, because the name itself is part of the
acronym, like it keeps going on and on forever! PHP is also a current pro-
gramming language that is often used on modern web sites and development
applications. PHP is extendible, strong, and works with many external utilities.
PHP is also pretty simple to learn. It is called a high-level language, which means
that it is between human language (English) and machine code (0s and 1s).
Because of this, you can easily understand it and write it almost like normal
writing, but it is also strong enough to do some seriously complex things.
So what can you actually do with PHP? You can make the Internet an interactive
experience by creating forms that people can fill out and submit and then deal
with the data however you like. For example, a visitor can email comments to a
webmaster, or post comments on site, or join a forum. PHP really makes the
Internet more usable.
To use this book, you only need a rudimentary knowledge of how to design a
web site. You need no programming background, but if you have done any
programming before, you will understand the language much more quickly. In
1
2 Chapter 1 n Welcome to PHP
fact, even if you have never developed a web site of any kind before, you will pick
up everything you need to know as we go along.
In this chapter, we are going to go ahead and install PHP. Installing PHP takes
two steps. First, you need to install a web server and second, you need to install
PHP as a part of the web server. Fortunately, both of these parts are free and on
the CD included in the back of this book. The specific installation steps are
different depending on whether you are installing on a Mac or a PC. Because
most readers will be using a PC, I will explain in depth how to install it on
Windows machines. Then I’ll give a few hints on how to install it for Macs.
Figure 1.1
The www.apache.org web site.
[PGP] [MD5]
n Other files
4 Chapter 1 n Welcome to PHP
Figure 1.2
The HTTP server web section.
Figure 1.3
Installing the Apache server.
Figure 1.4
The Apache configuration window.
6 Chapter 1 n Welcome to PHP
Figure 1.5
The Apache services monitor.
Installing PHP on Windows 7
This is the window you use to restart your web server. You need to do this
when working with PHP.
Testing Apache
Let’s test Apache and see if it works:
1. Open up your web browser.
Most Windows computers will have Internet Explorer installed, but I
recommend you download Mozilla Firefox. You can get this browser from
the CD, from www.maneeshsethi.com or, for the most updated version,
www.mozilla.com. Firefox is more compatible with web sites than Internet
Explorer.
2. Type localhost into the address bar.
Note that I did not include any .com or .net extension. If your web browser
looks like Figure 1.6, congratulations! You successfully installed your web
Figure 1.6
The successful installation page.
8 Chapter 1 n Welcome to PHP
page. If not, enter 127.0.0.1 instead of localhost. If it still does not work, try
installing again.
If your screen does look like this, you are ready to move on to the next
step—installing PHP.
Installing PHP
Follow these steps to install PHP:
1. Download the newest version of PHP you can find.
Check the CD, which has PHP 5.0.4; www.maneeshsethi.com; or (even
better) www.php.net.
2. Click the Downloads section.
You see a page that looks like Figure 1.7. Make sure your version of PHP is at
least 5.1.1; older versions are a little more difficult to set up.
3. Choose the Windows PHP zip package to go to the download page.
Figure 1.7
The PHP download page.
Installing PHP on Windows 9
Figure 1.8
The C:\php directory.
10 Chapter 1 n Welcome to PHP
Figure 1.9
The httpd.conf file.
7. Open httpd.conf.
You need to add a few lines to the document. Figure 1.9 shows what the
document looks like.
Caution
Be careful! Two files in the conf directory are similar: httpd.conf and httpd.default.conf.
Make sure you pick httpd.conf.
8. Scroll to the bottom of the httpd.conf file and add these lines:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
If you installed PHP to a different directory than C:\php, make sure you
substitute the name of the proper directory. All right! The installation
should be complete.
Installing PHP on Windows 11
Figure 1.10
A successful restart of Apache.
9. Right-click the Apache icon in the system tray and select Open Apache
Monitor; you should see the Apache services window.
10. Click the restart panel on the rightmost bar.
Hopefully, the web server restarts successfully. If it does not, go through the
previous steps, making sure that you did not make any errors. If the restart
was successful, your Apache services monitor should look like the one in
Figure 1.10.
Note that the window says The Apache2 service has restarted (meaning that
your httpd.conf file was properly formatted) and that the information bar at the
bottom of the monitor says PHP/5.0.4 (which may differ depending on your
version of PHP). If you don’t see this, try shutting down Apache and restarting
the service.
Testing PHP
We are going to see if PHP is actually fully working on your machine. Remember
when you typed in localhost and that web page came up? Well, that file was
located on your computer, in the Apache installation directory.
1. Go to the Apache directory, which is at C:\Program Files\Apache Group\
Apache2 by default.
12 Chapter 1 n Welcome to PHP
Figure 1.11
The Apache htdocs directory.
2. Open htdocs, whose contents should look a lot like Figure 1.11.
In this directory, you see a bunch of HTML files with different extensions.
Each of these files is identical to all the others, except they are translated
into different languages. Don’t worry about them though; you are creating
a new file.
3. Open your favorite text editor, such as Notepad or Wordpad—not
Microsoft Word.
4. Inside the file, type this:
<?php
phpinfo();
?>
Make sure you type it exactly correct, with the semicolon after the par-
enthesis. Using Notepad, the file should look like Figure 1.12.
Installing PHP on Windows 13
Figure 1.12
The phpinfo.php file.
Figure 1.13
The incorrectly loaded phpinfo.php file.
BRAN MUFFINS
(New England)
SCOTCH SCONES
Mix 3 teaspoons of baking powder with 3 cups of flour. Rub in 1
tablespoon of butter, add 1 cup of currants or raisins, 1 beaten
egg, and enough milk to make a paste to roll out. Cut into squares or
rounds and bake in a quick oven.
BLINNI
(Russian)
BAKED HOMINY
(New England)
A good way to prepare any cereal for children. Put a pint of milk with
2 teaspoons of sugar and one of salt in a saucepan on the fire—when
at the boiling point add 6 oz. of hominy; let it cook about ten minutes.
Remove the saucepan from the fire, add a tablespoonful of butter
and three eggs. Pour this into a baking pan and bake about 20
minutes.
Baked hominy may be served with meats or fish.
MARRONS GLACÉS
Put the chestnuts on the fire in cold water, boil 5 minutes, take them
out, and while hot strip them of their outer and inner skins. Put
them in a big saucepan containing a syrup of the proportion of ½ lb. of
sugar to 1 quart water and 1 teaspoonful of butter, when they come to
the boiling point remove to the back of the stove. Use a large quantity
of the syrup to the quantity of chestnuts. This syrup should diminish
very slowly. When it has become very thick take out the chestnuts and
drain them, add a little vanilla to the syrup. Now pour boiling water
over the chestnuts to remove the syrup which covers them. Dry them
well. Beat the thick syrup until it is opaque, then roll the dry chestnuts
in it; remove with a skimmer and let them dry on a sieve.
Prunes may be treated in the same way.
PRESERVED STRAWBERRIES
(French)
These berries will remain whole. Prepare a basin of lime water. When
the lime water is cool put in the strawberries and let them stand ¼
of an hour, then rinse them an instant in fresh water, drain them,
taking care not to bruise the fruit. Take an equal amount of sugar to
the amount of berries. To each pound of sugar, add 1 cup of water, boil
until a very thick syrup, then add the berries. Cook 5 minutes, pour
into sterilized jars and seal.
RHUBARB JELLY
(English)
BUDO CUP
To 1 pint bottle of dry ginger ale, add 1 pint bottle of grape juice, juice
of 1 orange, 1 lemon, 2 tablespoonsful of Jamaica rum, and 1 bottle
of effervescent water.
Transcriber's Note:
Varied hyphenation was retained.
This text uses the spelling of Curaçoa in place of the more usual
Curaçao.
Page 16, "excelent" changed to "excellent" (make an excellent)
Page 71, "Bechamel" changed to "Béchamel" (layer of Béchamel)
*** END OF THE PROJECT GUTENBERG EBOOK ALLIED COOKERY:
BRITISH, FRENCH, ITALIAN, BELGIAN, RUSSIAN ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
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.
ebookname.com