PHP 6/Mysql Programming for the Absolute Beginner

Total Page:16

File Type:pdf, Size:1020Kb

PHP 6/Mysql Programming for the Absolute Beginner PHP 6/MySQL® Programming for the Absolute Beginner Andy Harris Course Technology PTR A part of Cengage Learning Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States PHP 6/MySQL Programming for the © 2009 Course Technology, a part of Cengage Learning. Absolute Beginner: Andy Harris ALL RIGHTS RESERVED. No part of this work covered by the copyright Publisher and General Manager, Course herein may be reproduced, transmitted, stored, or used in any form or by Technology PTR: Stacy L. Hiquet any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, Associate Director of Marketing: information networks, or information storage and retrieval systems, except Sarah Panella as permitted under Section 107 or 108 of the 1976 United States Copyright Manager of Editorial Services: Act, without the prior written permission of the publisher. Heather Talbot Marketing Manager: Mark Hughes For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 Acquisitions Editor: Mitzi Koontz For permission to use material from this text or product, submit all Project Editor: Jenny Davidson requests online at cengage.com/permissions Further permissions questions can be emailed to [email protected] Technical Reviewer: Matt Telles PTR Editorial Services Coordinator: Erin Johnson PHP is a copyright of the PHP Group. MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries. Interior Layout Tech: Value Chain Firefox and Maguma Open Studio are registered trademarks of the Mozilla Foundation. HTML Validator is a registered trademark of the Massachusetts Cover Designer: Mike Tanamachi Institute of Technology, European Research Consortium for Informatics and CD-ROM Producer: Brandon Penticuff Mathematics, or Keio University on behalf of the World Wide Web Consor- tium. Aptana is a registered trademark of Aptana, Inc. Indexer: Larry Sweazy All other trademarks are the property of their respective owners. Proofreader: Sara Gullion Library of Congress Control Number: 2008928831 ISBN-13: 978-1-59863-798-4 ISBN-10: 1-59863-798-3 eISBN-10: 1-59863-826-2 Course Technology 25 Thomson Place Boston, MA 02210 USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international.cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd. For your lifelong learning solutions, visit courseptr.com Visit our corporate website at cengage.com Printed in Canada 1 2 3 4 5 6 7 11 10 09 To Heather, Elizabeth, Matthew, Jacob, and Benjamin, and to all those who have called me Teacher. ACKNOWLEDGMENTS irst, I thank my Lord and Savior Jesus Christ. FHeather, you always work harder on these books than I do. Thank you for your love and your support. Thank you Elizabeth, Matthew, Jacob, and Benjamin for understanding why Dad was typing all the time. Thanks to the Open Source community for creating great free software like PHP and MySQL. Thank you, Stacy Hiquet, for your continued support and encouragement on this and other projects. Thanks to Mitzi Koontz, for seeing this project through, and to Jenny Davidson for your work as the project editor. Special thanks to Matt Telles for the outstanding technical edit. You made the book far better than it would have been before. Thanks to all who worked on the previous two editions. Your hard work was the foundation for something that might be even better. Thank you to the many members of the Course Technology PTR team who worked on this book. A huge thanks goes to my students throughout the years and the many people who sent in comments and advice from the first two editions. Thank you for being patient with my manuscript, for helping me spot many errors, and for providing invaluable advice. I learned as much from you as you did from me. ABOUT THE AUTHOR ndy Harris began his teaching career as a high-school special education Ateacher. During that time, he taught himself enough computing to do part- time computer consulting and database work. He began teaching comput- ing at the university level in the late 1980s as a part-time job. Since 1995 he has been a full-time lecturer in the Computer Science Department of Indiana University/Purdue University–Indianapolis, where he serves as a senior lecturer and teaches classes in several programming languages. His primary interests are web development, PHP, Java, game programming, virtual reality, portable devices, and streaming media. He has written numerous books on these and other tech- nology topics. This page intentionally left blank Table of Contents Chapter 1 Exploring the Environment..................................... 1 Programming on the Web Server...................................................................................... 3 Installing PHP and Apache ......................................................................................... 4 Using an Existing Server.............................................................................................. 4 Installing Your Own Development Environment................................................. 5 Installing with XAMPP................................................................................................. 7 Starting Your Server ..................................................................................................... 8 Checking Your Security Settings............................................................................... 9 Configuring Apache.................................................................................................... 10 Running Your Local Server................................................................................................ 11 Adding PHP to Your Pages......................................................................................... 11 Examining the Results............................................................................................... 12 Display Errors............................................................................................................... 16 Windows Extensions .................................................................................................. 17 Changes in PHP 6......................................................................................................... 19 Safe Mode....................................................................................................................... 19 Register Globals ........................................................................................................... 19 Creating the Tip of the Day Program............................................................................. 19 Summary................................................................................................................................ 20 Chapter 2 Using Variables and Input...................................... 21 Introducing the Story Program........................................................................................ 21 Using Variables in Your Scripts........................................................................................ 23 Introducing the Hi Jacob Program ......................................................................... 23 Creating a String Variable................................................................................................. 25 Naming Your Variables.............................................................................................. 25 Assigning a Value to a Variable ............................................................................... 25 Printing a Variable’s Value ....................................................................................... 26 Using Variables for More Complex Pages...................................................................... 28 Building the Row Your Boat Page ........................................................................... 28 Creating Multi-Line Strings ...................................................................................... 30 Working with Numeric Variables.................................................................................... 31 Making the ThreePlusFive Program ....................................................................... 31 viii PHP 6/MySQL Programming for the Absolute Beginner Assigning Numeric Values........................................................................................ 33 Using Mathematical Operators................................................................................ 33 Creating a Form to Ask a Question................................................................................. 34 Building an HTML Page with a Form ..................................................................... 35 Setting the Action Attribute to a Script File ........................................................ 36 Writing a Script to Retrieve the Data .................................................................... 37 Sending Data without a Form.......................................................................................... 39 Understanding the get Method ..............................................................................
Recommended publications
  • Resin 3.2 Reference
    Contents 1 Overview 3 1.1 Features - Resin and Resin Professional . .3 2 Installation 11 2.1 Resin Installation Quick Start . 11 2.2 Resin Installation . 16 2.3 Resin Web Server . 16 2.4 Resin with Apache . 22 2.5 Resin with IIS . 34 2.6 How the Plugins Dispatch to Resin . 44 3 Command-Line 47 3.1 Command-Line Configuration . 47 4 Admin Guide 51 4.1 User Guide: Administration . 51 5 Watchdog 63 5.1 Resin Watchdog . 63 6 Virtual Hosts 73 6.1 Virtual Hosting . 73 7 Clustering 89 7.1 Resin Clustering . 89 8 Web Applications 109 8.1 An Overview of Web Applications . 109 9 Logging 137 9.1 Log . 137 10 Administration 163 10.1 Resin Administration . 163 1 CONTENTS 11 Deployment 177 11.1 Packaging/Deployment . 177 12 Proxy Caching 181 12.1 Server Caching . 181 13 Quercus 193 13.1 Quercus: PHP in Java . 193 14 Security 217 14.1 Resin Security . 217 15 Inversion of Control 271 15.1 Resin IoC . 271 15.2 Scheduled Task . 308 16 Amber 327 16.1 Amber . 327 17 Embedding Resin 355 17.1 Embedding Resin . 355 18 Filters 367 18.1 Filters . 367 19 BAM 379 19.1 BAM . 379 20 Comet 405 20.1 Comet/Server-Push Servlet . 405 21 Remoting 411 21.1 Resin Remoting . 411 21.2 Hessian . 417 22 Messaging 423 22.1 Resin Messaging . 423 23 JSF - Java Server Faces 435 23.1 JSF - Java Server Faces . 435 24 Configuration Tags 445 24.1 cluster: Cluster tag configuration .
    [Show full text]
  • Maximum Internet Security: a Hackers Guide - Networking - Intrusion Detection
    - Maximum Internet Security: A Hackers Guide - Networking - Intrusion Detection Exact Phrase All Words Search Tips Maximum Internet Security: A Hackers Guide Author: Publishing Sams Web Price: $49.99 US Publisher: Sams Featured Author ISBN: 1575212684 Benoît Marchal Publication Date: 6/25/97 Pages: 928 Benoît Marchal Table of Contents runs Pineapplesoft, a Save to MyInformIT consulting company that specializes in Internet applications — Now more than ever, it is imperative that users be able to protect their system particularly e-commerce, from hackers trashing their Web sites or stealing information. Written by a XML, and Java. In 1997, reformed hacker, this comprehensive resource identifies security holes in Ben co-founded the common computer and network systems, allowing system administrators to XML/EDI Group, a think discover faults inherent within their network- and work toward a solution to tank that promotes the use those problems. of XML in e-commerce applications. Table of Contents I Setting the Stage 1 -Why Did I Write This Book? 2 -How This Book Will Help You Featured Book 3 -Hackers and Crackers Sams Teach 4 -Just Who Can Be Hacked, Anyway? Yourself Shell II Understanding the Terrain Programming in 5 -Is Security a Futile Endeavor? 24 Hours 6 -A Brief Primer on TCP/IP 7 -Birth of a Network: The Internet Take control of your 8 -Internet Warfare systems by harnessing the power of the shell. III Tools 9 -Scanners 10 -Password Crackers 11 -Trojans 12 -Sniffers 13 -Techniques to Hide One's Identity 14 -Destructive Devices IV Platforms
    [Show full text]
  • PHP Programming Cookbook I
    PHP Programming Cookbook i PHP Programming Cookbook PHP Programming Cookbook ii Contents 1 PHP Tutorial for Beginners 1 1.1 Introduction......................................................1 1.1.1 Where is PHP used?.............................................1 1.1.2 Why PHP?..................................................2 1.2 XAMPP Setup....................................................3 1.3 PHP Language Basics.................................................5 1.3.1 Escaping to PHP...............................................5 1.3.2 Commenting PHP..............................................5 1.3.3 Hello World..................................................6 1.3.4 Variables in PHP...............................................6 1.3.5 Conditional Statements in PHP........................................7 1.3.6 Loops in PHP.................................................8 1.4 PHP Arrays...................................................... 10 1.5 PHP Functions.................................................... 12 1.6 Connecting to a Database............................................... 14 1.6.1 Connecting to MySQL Databases...................................... 14 1.6.2 Connecting to MySQLi Databases (Procedurial).............................. 14 1.6.3 Connecting to MySQLi databases (Object-Oriented)............................ 15 1.6.4 Connecting to PDO Databases........................................ 15 1.7 PHP Form Handling................................................. 15 1.8 PHP Include & Require Statements.........................................
    [Show full text]
  • Microsoft Frontpage Course Design 2000-2001
    Microsoft FrontPage Course Design 2000-2001 Course Information Organization: EASTERN ARIZONA COLLEGE Division: General Education Course Number: CMP Title: Microsoft FrontPage Credits: 1 Developed by: Dr. Barbara Ganz Lecture/Lab Ratio: 1 Lec/1 Lab Transfer Status: Non-Transferable to ASU, UofA and NAU Extended Registration Class: Not an extended registration course CIP Code: 52.0408 Awareness Course: No Intensive Writing Course: No Prerequisites: 1. None Educational Value: This class is designed for Intermediate Computer and Internet users who desire to learn the basic of web site development. Goals: 1. To introduce students to the uses of Microsoft FrontPage. Description: An introduction to web page development using Microsoft FrontPage in a non-programming approach. Includes hyperlinks, graphic, frames, tables, ftp. Emphasis on good website design strategies. Experience using the Internet and basic computers skills are recommended. Textbooks: Joyce Fox and Christina Dudley. Quick Course in Microsoft FrontPage 2000. Microsoft Press, Supplies: None Microsoft FrontPage 1 CMP April '02 Competencies and Performance Standards 1. Define a website and web page and describe their basic elements. Domain--Cognitive Level--Evaluation Importance--Useful Difficulty--Low Criteria--Performance will be Conditions--Competence will be Learning Objectives: satisfactory when: demonstrated: a. Define website, web page, and • learner can define website, web • By oral report in a class other applicable Internet terms. page, and other applicable discussion. b. Explain the characteristics of an Internet terms. effective website and web page. • learner can explain the c. Describe the basic elements of a characteristics of an effective web page. website and web page. • learner can describe the basic elements of a web page.
    [Show full text]
  • Copyrighted Material
    05_096970 ch01.qxp 4/20/07 11:27 PM Page 3 1 Introducing Cascading Style Sheets Cascading style sheets is a language intended to simplify website design and development. Put simply, CSS handles the look and feel of a web page. With CSS, you can control the color of text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what back- ground images or colors are used, as well as a variety of other visual effects. CSS was created in language that is easy to learn and understand, but it provides powerful control over the presentation of a document. Most commonly, CSS is combined with the markup languages HTML or XHTML. These markup languages contain the actual text you see in a web page — the hyperlinks, paragraphs, headings, lists, and tables — and are the glue of a web docu- ment. They contain the web page’s data, as well as the CSS document that contains information about what the web page should look like, and JavaScript, which is another language that pro- vides dynamic and interactive functionality. HTML and XHTML are very similar languages. In fact, for the majority of documents today, they are pretty much identical, although XHTML has some strict requirements about the type of syntax used. I discuss the differences between these two languages in detail in Chapter 2, and I also pro- vide a few simple examples of what each language looks like and how CSS comes together with the language to create a web page. In this chapter, however, I discuss the following: ❑ The W3C, an organization that plans and makes recommendations for how the web should functionCOPYRIGHTED and evolve MATERIAL ❑ How Internet documents work, where they come from, and how the browser displays them ❑ An abridged history of the Internet ❑ Why CSS was a desperately needed solution ❑ The advantages of using CSS 05_096970 ch01.qxp 4/20/07 11:27 PM Page 4 Part I: The Basics The next section takes a look at the independent organization that makes recommendations about how CSS, as well as a variety of other web-specific languages, should be used and implemented.
    [Show full text]
  • Microsoft® Frontpage® 2002 Tutorial Contents
    Microsoft FrontPage 2002 Tutorial Contents Introduction ................................ ................................ ................................ ..................... 2 Before You Begin ................................ ................................ ................................ ........ 2 Overview ................................ ................................ ................................ ................. 2 If you have Web server software installed ................................ ................................ 3 FrontPage and Microsoft Internet Explorer ................................ .............................. 3 If you are using Windows NT ® Workstation 4.0 or Windows NT Server 4.0 ............. 3 What You Will Learn ................................ ................................ ................................ .... 3 Lesson 1: Creating Web Pages ................................ ................................ ............... 3 Lesson 2: Enhancing and Publishing a Web Site ................................ ..................... 4 Learning More About FrontPage ................................ ................................ ................. 4 Lesson 1 Creating Web Pages ................................ ................................ ....................... 6 Overview ................................ ................................ ................................ ..................... 6 Opening FrontPage ................................ ................................ ...............................
    [Show full text]
  • Cakephp Cookbook Documentation Release 4.X
    CakePHP Cookbook Documentation Release 4.x Cake Software Foundation Sep 25, 2021 Contents 1 CakePHP at a Glance 1 Conventions Over Configuration........................................1 The Model Layer................................................1 The View Layer.................................................2 The Controller Layer..............................................2 CakePHP Request Cycle............................................3 Just the Start...................................................4 Additional Reading...............................................4 2 Quick Start Guide 13 Content Management Tutorial......................................... 13 CMS Tutorial - Creating the Database..................................... 15 CMS Tutorial - Creating the Articles Controller................................ 19 3 4.0 Migration Guide 29 Deprecated Features Removed......................................... 29 Deprecations.................................................. 29 Breaking Changes................................................ 31 New Features.................................................. 37 4 Tutorials & Examples 41 Content Management Tutorial......................................... 41 CMS Tutorial - Creating the Database..................................... 43 CMS Tutorial - Creating the Articles Controller................................ 47 CMS Tutorial - Tags and Users......................................... 56 CMS Tutorial - Authentication......................................... 64 CMS Tutorial - Authorization.........................................
    [Show full text]
  • Complete PHP Secrets & Tips for Professionals
    PHP CompleteComplete Tips & Secrets for Professionals TipsPHP & Secrets for Professionals 300+ pages of professional hints and tricks Disclaimer This is an unocial free book created for educational purposes and is GoalKicker.com not aliated with ocial PHP group(s) or company(s). Free Programming Books All trademarks and registered trademarks are the property of their respective owners Contents About ................................................................................................................................................................................... 1 Chapter 1: Getting started with PHP ................................................................................................................... 2 Section 1.1: HTML output from web server .................................................................................................................. 2 Section 1.2: Hello, World! ............................................................................................................................................... 3 Section 1.3: Non-HTML output from web server ........................................................................................................ 3 Section 1.4: PHP built-in server ..................................................................................................................................... 4 Section 1.5: PHP CLI ......................................................................................................................................................
    [Show full text]
  • Virtual Wishlist
    Virtual Wishlist Figure 1: Welcome Page of the Virtual Wishlist Group project carried out by Josua Dietrich, Nils Braune and Tino Canziani created 2011 at D-ITET, ETH Zürich 21.12.2011 Contents 1 Introduction and Background 3 1.1 Idea . .3 1.2 Related Work . .3 1.3 Tools . .3 2 Concept 5 2.1 Core functions . .5 2.2 Website Layout . .5 2.3 Sessions & Proles . .7 3 Implementation 8 3.1 HTML/Login/Session (Welcome.html) . .8 3.2 MySQL server: creating a database . .9 3.3 setupConnection.php . 11 3.4 $.ajax(), getWishlists() .................. 12 3.5 Adding a prole picture . 14 4 Results and Future Steps 16 4.1 Results . 16 4.1.1 Welcome Page . 16 4.1.2 Prole Page . 16 4.1.3 my Wishes menu . 16 4.1.4 my Friends and Search Friends Menu . 16 4.1.5 Settings menu . 17 4.1.6 Friend Page . 17 4.1.7 Terms, Privacy, About, Help Page . 17 4.1.8 Process of fullling and getting wishes fullled . 17 4.1.9 Security . 17 4.2 Future steps . 18 A Server/PHP functions 20 B Screenshot of the prole page 21 C Setting up the Virtual Wishlist step by step 22 D Endnotes 23 1 Abstract In this group project we designed and implemented a virtual wish list as a social media service on the web. It enables its users to maintain a personal prole, create their own wish lists or opt to grant other friends their specic wishes. The use case of this virtual wish list will mostly tend to birthday and christmas events, social gatherings, leisure activities or work related events.
    [Show full text]
  • Gender and Web Design Software
    Gender and web design software Gabor HORVATH Gloria MOSS Rod GUNN Eszter VASS Glamorgan Business School University of Glamorgan Pontypridd, Wales CF37 1DL, UK ABSTRACT been extensively studied [17] but a relatively unexplored field concerns itself with the non-interpretive elements of navigation, There are several studies dealing with the differences between content, form and colours. sites originated by men and women. However, these references are mainly related to the “output”, the final web site. In our Web-design research we examined the input side of web designing. We Summarizing the work on web-design aesthetics, a recent study thoroughly analysed a number of randomly selected web refers to the relative ‘paucity of research’ [12], with ‘no designer softwares to see, whether and to what extent the principles of good www design ... set in stone’ [9] The fact that templates they offer determine the final look of an individual’s some web design is perceived as less than optimum is website. We have found that most of them are typical masculine demonstrated by the fact that the 10 factors with the greatest templates, which makes it difficult to any women to design a deficit amongst Internet users in the US and Netherlands feminine looking website. It can be one of the reasons of the included a factor relating to graphics [20]. masculine website hegemony on the web. The design of websites can most easily be affected by IT Key words: Internet, gender differences, web aesthetics, web professionals. This is a profession in which participation rates design, websites for women, across the board, have fluctuated during the 1990s somewhere between 19% and 22% [15].
    [Show full text]
  • Sethesaurus: Wordnet in Software Engineering
    This is the author's version of an article that has been published in this journal. Changes were made to this version by the publisher prior to publication. The final version of record is available at http://dx.doi.org/10.1109/TSE.2019.2940439 IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. 14, NO. 8, AUGUST 2015 1 SEthesaurus: WordNet in Software Engineering Xiang Chen, Member, IEEE, Chunyang Chen, Member, IEEE, Dun Zhang, and Zhenchang Xing, Member, IEEE, Abstract—Informal discussions on social platforms (e.g., Stack Overflow, CodeProject) have accumulated a large body of programming knowledge in the form of natural language text. Natural language process (NLP) techniques can be utilized to harvest this knowledge base for software engineering tasks. However, consistent vocabulary for a concept is essential to make an effective use of these NLP techniques. Unfortunately, the same concepts are often intentionally or accidentally mentioned in many different morphological forms (such as abbreviations, synonyms and misspellings) in informal discussions. Existing techniques to deal with such morphological forms are either designed for general English or mainly resort to domain-specific lexical rules. A thesaurus, which contains software-specific terms and commonly-used morphological forms, is desirable to perform normalization for software engineering text. However, constructing this thesaurus in a manual way is a challenge task. In this paper, we propose an automatic unsupervised approach to build such a thesaurus. In particular, we first identify software-specific terms by utilizing a software-specific corpus (e.g., Stack Overflow) and a general corpus (e.g., Wikipedia). Then we infer morphological forms of software-specific terms by combining distributed word semantics, domain-specific lexical rules and transformations.
    [Show full text]
  • Variables En PHP 5
    Manual Imprescindible de PHP5 Luis Miguel Cabezas Granado Prólogo de Zeev Suraski y Andi Gutmans ANAYA MULTIMEDIA Agradecimientos Finalizar este libro ha sido una odisea donde han intervenido muchas personas y factores, mudanza incluida. Para empezar me gustaría agradecer a Marta Camarero y a Eugenio Tuya su fe en mí como escritor. Me dieron ánimos desde el principio y un poquito de prisa. A Zeev Suraski y Andi Gutmans, creadores de PHP 5, por crear el lengua­ je y tratarme como a uno de los suyos en los ¿seminar de www.zend.com. Además, tengo que agradecerles la rapidez con la que escribieron el pró­ logo del libro. A Marco Tabini, director de la revista canadiense PHParchitect, por en­ viarme el manual de Certificación PHP en papel y no en PDF. A Tim Converse y Joyce Park por escribir PHP5 and MySQL Bible, cuyos conocimientos me bebí en apenas 3 días. A Harry Fuecks por escribir el mejor libro de PHP de todos los tiempos The PHP Anthology, que me hizo reorientar todos los esfuerzos a la inno­ vación. A la Asociación Regional de Universidades Populares de Extremadura (AUPEX) por probar todos mis programas escritos en PHP (libros de visita, foros, nccproject, newton, etcétera). Espero dar algún día con la tecla. A mis compañeros de trabajo Pako, Palomo, Javi y Pedro por las largas horas de discusión en torno a Delphi, Java, C# y, por supuesto, PHP. A Justo Cabezas, porque todo lo que me regaló fueron libros de informá­ tica, y encima escritos por él. Sigo tus pasos. A los grupos de usuario de gnuLinux de Extremadura www.sinuh.org y www.gulex.org, por ser una fuente inagotable de conocimientos.
    [Show full text]