Introduction to web development with PHP

Similar documents
Chapter 1. Introduction to web development and PHP. 2010, Mike Murach & Associates, Inc. Murach's PHP and MySQL, C1

How to code a PHP application

Instructor s Notes Web Data Management Web Client/Server Concepts. Web Data Management Web Client/Server Concepts

CS637 Midterm Review

Introduction to Web Application Development, for CS437/637. Instructor: Betty O Neil

Introduction to Web Application Development, for CS437/637. Internet Users. How the Internet evolved. A Hierarchy of Networks

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

HTML MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

Lab Introduction to Cascading Style Sheets

A database-driven web site

The MANUAL. 1 P a g e

Web Structure and Style. MB2030 Section 2 Class 4

CSS worksheet. JMC 105 Drake University

Layout with Layers and CSS

Let's Play... Try to name the databases described on the following slides...

FUNDAMENTALS OF WEB DESIGN (46)

Stamp Builder. Documentation. v1.0.0

Introduction to using HTML to design webpages

Lab 1: Introducing HTML5 and CSS3

JSN PageBuilder 3 Configuration Manual Introduction

Taking Fireworks Template and Applying it to Dreamweaver

IBM Forms V8.0 Custom Themes IBM Corporation

Designing the Home Page and Creating Additional Pages

Multimedia Systems and Technologies Lab class 6 HTML 5 + CSS 3

Web Programming Paper Solution (Chapter wise)

HIERARCHICAL ORGANIZATION

Basics of Web. First published on 3 July 2012 This is the 7 h Revised edition

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

Figure 1 Properties panel, HTML mode

Dreamweaver CS3 Lab 2

Unit 10 - Client Side Customisation of Web Pages. Week 5 Lesson 1 CSS - Selectors

Dreamweaver CS 5.5. University Information Technology Services. Training, Outreach, Learning Technologies, and Video Production

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

Getting Started with Eric Meyer's CSS Sculptor 1.0

Software Platforms. Quiz with Explainations. Hans-Petter Halvorsen, M.Sc.

CS WEB TECHNOLOGY

Web Site Design and Development. CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM

How to lay out a web page with CSS

Cascading Style Sheet. Styles as Tag Attributes. Syntax. <h1>: what font type/size is used? STYLE = SELECTOR {RULES} Attributes such as bgcolor

Introduction to WEB PROGRAMMING

Chapter 3 How to use HTML5 and CSS3 with ASP.NET applications

Santa Tracker. Release Notes Version 1.0

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

Tutorial 4. Activities. Code o Editor: Expression Web o Focus : Base Layout, navigation with folders, external stylesheets, Open up Expression Web

Internet programming Lab. Lecturer Mariam A. Salih

CSS Cascading Style Sheets

ENGINEERING DATA HUB VISUAL DESIGN SPECIFICATIONS VERSION 3. Created: 2/10/2017

Dreamweaver CS6. Table of Contents. Setting up a site in Dreamweaver! 2. Templates! 3. Using a Template! 3. Save the template! 4. Views!

Tutorial. Activities. Code o o. Editor: Notepad Focus : Text manipulation & webpage skeleton. Open Notepad

<style type="text/css"> <!-- body {font-family: Verdana, Arial, sans-serif} ***set font family for entire Web page***

Ektron Advanced. Learning Objectives. Getting Started

Creating a Job Aid using HTML and CSS

Web Publishing Basics I

Getting Started with PHP

Creating HTML files using Notepad

Using Dreamweaver CS6

To illustrate how to set TAG styles the <body> and <h1> tags (for the BODY and the HEADING 1 styles) will be adjusted.

CSS.

Scripting. Web Architecture and Information Management [./] Spring 2009 INFO (CCN 42509) Contents

Cascading Style Sheets Level 2

CMS and e-commerce Solutions. version 1.0. Please, visit us at: or contact directly by

Perfect Student Midterm Exam March 20, 2007 Student ID: 9999 Exam: 7434 CS-081/Vickery Page 1 of 5

Section 1. How to use Brackets to develop JavaScript applications

PCC Local File Viewer User Guide. Version /23/2015 Copyright 2015

Teach Yourself HTML5 & CSS 3: Week 5 Task 13 - Anchors Part 3

AGENDA. EMBEDDING FONTS [ Font Files & CSS font-family ] :: Online Font Converter :: ADD font-family css code to style.css

Prepared: 28 th February 2006 Program Version: swmenupro4.2+ for Joomla/Mambo

Internet: An international network of connected computers. The purpose of connecting computers together, of course, is to share information.

GIMP WEB 2.0 MENUS. Before we begin this tutorial let s visually compare a standard navigation bar and a web 2.0 navigation bar.

powered by Series of Tubes Senator Ted Stevens talking about the Net Neutrality Bill Jul 17, powered by

Overview of the Adobe Dreamweaver CS5 workspace

AGENDA :: MULTIMEDIA TOOLS :: CLASS NOTES

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website.

Chapter 2 How to structure a web application with the MVC pattern

McMaster Brand Standard for Websites

5 Snowdonia. 94 Web Applications with C#.ASP

READSPEAKER ENTERPRISE HIGHLIGHTING 2.5

ADOBE DREAMWEAVER CS4 BASICS

Chapter 2. Self-test exercises

Perceptive DataTransfer

HTML and CSS MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

Slide 1. Chapter 5. How to use the MVC pattern to organize your code. 2010, Mike Murach & Associates, Inc. Murach's PHP and MySQL, C5

How to structure a web application with the MVC pattern

How to use PHP with a MySQL database

11. HTML5 and Future Web Application

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

Web Development IB PRECISION EXAMS

Introduction to the Internet

Building Your Website

Intermediate Web Publishing: Working with Styles

The Dreamweaver Interface

SeaMonkey Composer: Creating Web Pages

Lab 4 CSS CISC1600, Spring 2012

Assignments (4) Assessment as per Schedule (2)

Languages in WEB. E-Business Technologies. Summer Semester Submitted to. Prof. Dr. Eduard Heindl. Prepared by

Microsoft Expression Web Quickstart Guide

XAMPP Web Development Stack

DREAMWEAVER QUICK START TABLE OF CONTENT

How to use the MVC pattern to organize your code

servlets and Java JSP murach s (Chapter 2) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach

Transcription:

Chapter 1 Introduction to web development with PHP Objectives (continued) Knowledge 9. Describe the benefits of using an IDE like NetBeans for application development. 2017, Mike Murach & Associates, Inc. C1, Slide 1 2017, Mike Murach & Associates, Inc. C1, Slide 4 Objectives The architecture of a web application Applied 1. Use the XAMPP control panel to start or stop Apache or MySQL when it is running on your own computer. 2. Deploy a PHP application on your own computer. 3. Run a web application that s on your own computer (1) by entering its URL into the address bar of a browser or (2) by getting and using an index of the applications that are on the web server. 4. View the source code for a web page in a web browser. 2017, Mike Murach & Associates, Inc. C1, Slide 2 2017, Mike Murach & Associates, Inc. C1, Slide 5 Objectives (continued) Knowledge 1. Describe the components of a client-server architecture. 2. Describe HTTP requests and responses. 3. Distinguish between the way a web server processes static web pages and dynamic web pages. 4. Explain what these software components do as a web application runs: Apache, PHP, Chrome, and MySQL. 5. Describe the difference between MySQL and MariaDB. 6. Describe the way a PHP application is deployed on your own computer or on an Internet server. 7. Describe the components of an HTTP URL. 8. Describe what happens if you omit one or more parts of a URL when you try to run an application or if you code a URL that specifies a directory that doesn t contain a default page. The architecture of the Internet WAN WAN IXP IXP IXP WAN WAN 2017, Mike Murach & Associates, Inc. C1, Slide 3 2017, Mike Murach & Associates, Inc. C1, Slide 6 1

Key terms server client network router Local Area Network () Wide Area Network (WAN) Internet Internet Exchange Point (IXP) Internet Service Provider (ISP) Two protocols that web applications depend upon HyperText Transfer Protocol (HTTP) Transmission Control Protocol/Internet Protocol (TCP/IP) 2017, Mike Murach & Associates, Inc. C1, Slide 7 2017, Mike Murach & Associates, Inc. C1, Slide 10 How static web pages are processed How dynamic web pages are processed with PHP HTTP request HTTP response Web Browser Web Server Database Server PHP Script 2017, Mike Murach & Associates, Inc. C1, Slide 8 2017, Mike Murach & Associates, Inc. C1, Slide 11 A simple HTTP request GET / HTTP/1.1 Host: www.example.com A simple HTTP response HTTP/1.1 200 OK Content-Type: text/html Content-Length: 136 Server: Apache/2.2.3 <html> <head> <title>example Web Page</title> </head> <body> <p>this is a sample web page</p> </body> </html> Key terms HyperText Markup Language (HTML) static web page HTTP request HTTP response. dynamic web page PHP interpreter database server render round trip 2017, Mike Murach & Associates, Inc. C1, Slide 9 2017, Mike Murach & Associates, Inc. C1, Slide 12 2

Web browsers Chrome Firefox Internet Explorer Edge Safari Opera Web servers Apache IIS 2017, Mike Murach & Associates, Inc. C1, Slide 13 Highlights in the history of MySQL Version Year Description 3.23 1995 The original version of MySQL 4.0 2003 Introduced support for unions. 4.1 2004 Introduced support for subqueries and prepared statements. 5.0 2005 Introduced support for stored procedures, triggers, views, and transactions. 5.1 2008 Introduced support for row-based replication and server log tables. 5.5 2010 Default storage engine now supports referential integrity. 5.6 2011 Introduced support for big data. 5.7 2017 Included security improvements and other enhancements. 2017, Mike Murach & Associates, Inc. C1, Slide 16 Server-side languages PHP JSP ASP.NET Perl Python Database servers MySQL Oracle DB2 MS SQL Server MySQL notes MySQL is owned and sponsored by MySQL AB, a for-profit firm. In 2008, Sun Microsystems acquired MySQL AB. In 2009, Oracle Corporation acquired Sun Microsystems. In 2009, many of the original developers of MySQL left MySQL AB and begin working on different forks of the open-source code. One of the most popular of these forks is MariaDB. In 2012, several Linux distributions, as well as Wikipedia and Google, began to replace MySQL with MariaDB. MariaDB intends to maintain high compatibility with MySQL so it can work as a drop-in replacement for MySQL. XAMPP 5.6 and later include MariaDB, not MySQL. 2017, Mike Murach & Associates, Inc. C1, Slide 14 2017, Mike Murach & Associates, Inc. C1, Slide 17 Highlights in the history of PHP Version Year Description 2 1995 Personal Home Page 3 1998 PHP: Hypertext Processor 4 2000 Introduced the Zend Engine 5 2004 Introduced the Zend Engine 2 Improved support for OOP Added the PHP Data Objects extension 6 N/A Abandoned and never released 7 2015 Introduced the Zend Engine 3 Improved performance The first page of an application 2017, Mike Murach & Associates, Inc. C1, Slide 15 2017, Mike Murach & Associates, Inc. C1, Slide 18 3

The second page (display_discount.php) The CSS file (main.css) body { font-family: Arial, Helvetica, sans-serif; margin: 1em; padding: 0; main { display: block; width: 450px; margin: 0 auto; padding: 1.5em; background: white; border: 2px solid navy; h1 { color: navy; label { width: 10em; padding-right: 1em; float: left; 2017, Mike Murach & Associates, Inc. C1, Slide 19 2017, Mike Murach & Associates, Inc. C1, Slide 22 The HTML file (index.html) <!DOCTYPE html> <html> <head> <title>product Discount Calculator</title> <link rel="stylesheet" type="text/css" href="main.css"> </head> <body> <main> <h1>product Discount Calculator</h1> <form action="display_discount.php" method="post"> <div id="data"> <label>product Description:</label> <input type="text" name="product_description"><br> <label>list Price:</label> <input type="text" name="list_price"><br> The CSS file (main.css) (continued) #data input { float: left; width: 15em; margin-bottom:.5em; #data span { padding-left:.25em; #buttons input { float: left; margin-bottom:.5em; br { clear: left; 2017, Mike Murach & Associates, Inc. C1, Slide 20 2017, Mike Murach & Associates, Inc. C1, Slide 23 The HTML file (index.html) (continued) </form> </main> </body> </html> <label>discount Percent:</label> <input type="text" name="discount_percent"> <span>%</span><br> </div> <div id="buttons"> <label> </label> <input type="submit" value="calculate Discount"><br> </div> The PHP file (display_discount.php) <?php // get the data from the form $product_description = $_POST['product_description']; $list_price = $_POST['list_price']; $discount_percent = $_POST['discount_percent']; // calculate the discount $discount = $list_price * $discount_percent *.01; $discount_price = $list_price - $discount; // apply currency formatting to the dollar and percent amounts $list_price_formatted = "$".number_format($list_price, 2); $discount_percent_formatted = number_format ($discount_percent, 1)."%"; $discount_formatted = "$".number_format($discount, 2); $discount_price_formatted = "$".number_format($discount_price,2);?> // escape the unformatted input $product_description_escaped = htmlspecialchars($product_description); 2017, Mike Murach & Associates, Inc. C1, Slide 21 2017, Mike Murach & Associates, Inc. C1, Slide 24 4

The PHP file (display_discount.php) (continued) <!DOCTYPE html> <html> <head> <title>product Discount Calculator</title> <link rel="stylesheet" type="text/css" href="main.css"> </head> <body> <main> <h1>product Discount Calculator</h1> <label>product Description:</label> <span><?php echo $product_description_escaped;?></span><br> <label>list Price:</label> <span><?php echo $list_price_formatted;?></span><br> How to open files in Notepad++ Use the Open button in the toolbar. Right-click on the file in Windows Explorer and select Edit with Notepad++. How to save the current file Use the Save button in the toolbar. Press Ctrl+S. How to save all open files Use the Save All button. 2017, Mike Murach & Associates, Inc. C1, Slide 25 2017, Mike Murach & Associates, Inc. C1, Slide 28 The PHP file (display_discount.php) (continued) <label>standard Discount:</label> <span><?php echo $discount_percent_formatted;?></span><br> <label>discount Amount:</label> <span><?php echo $discount_formatted;?></span><br> <label>discount Price:</label> <span><?php echo $discount_price_formatted;?></span><br> </main> </body> </html> How to close the current file in Notepad++ Use the Close button in the toolbar. How to close all open files Use the Close All button. How to open a new file in a new tab Use the New button in the toolbar. 2017, Mike Murach & Associates, Inc. C1, Slide 26 2017, Mike Murach & Associates, Inc. C1, Slide 29 Notepad++ with three tabs open How to change the Notepad++ style for comments Start the Settings Styler Configurator command. Select PHP in the language list and COMMENT in the style list. Change the font name and font size in the drop-down lists to the blank entries at the top of the lists. Repeat this for COMMENTLINE for the PHP language, for COMMENT for the HTML language, and for COMMENT for the CSS language. 2017, Mike Murach & Associates, Inc. C1, Slide 27 2017, Mike Murach & Associates, Inc. C1, Slide 30 5

The XAMPP control panel The directories for a PHP app on a local server xampp htdocs (the document root directory) guitar_store (the application root directory) admin catalog styles images index.php 2017, Mike Murach & Associates, Inc. C1, Slide 31 2017, Mike Murach & Associates, Inc. C1, Slide 34 How to start the XAMPP control panel Select the XAMPP Control Panel item from the Windows Start menu or double-click on the XAMPP icon on your desktop. How to start and stop Apache or MySQL Click on its Start or Stop button. To start Apache or MySQL automatically when your computer starts, click the Services button in the XAMPP control panel. 2017, Mike Murach & Associates, Inc. C1, Slide 32 The structure for book_apps and ex_starts xampp htdocs book_apps ch01_product_discount ch02_product_discount ch02_future_value ch04_product_list ch04_product_manager... ex_starts ch02_ex1 ch02_ex2 ch04_ex1... 2017, Mike Murach & Associates, Inc. C1, Slide 35 About XAMPP XAMPP is a free, open-source web server package. The package consists of Apache, MySQL, and interpreters for PHP. XAMPP can be easily installed. XAMPP is available for Windows, Linux, Solaris, and Mac OS X systems (the X in XAMPP stands for cross-platform). How to deploy a PHP application on a local server Copy all of the directories and files for an application to the \xampp\htdocs directory on the server. How to deploy the downloadable applications on a local server Copy the book_apps and ex_starts directories and all their contents to the \xampp\htdocs directory on the server. How to deploy an application on an Internet server Use an FTP (File Transfer Protocol) program to upload the tested directories and files to the htdocs directory of the Apache web server. 2017, Mike Murach & Associates, Inc. C1, Slide 33 2017, Mike Murach & Associates, Inc. C1, Slide 36 6

The components of an HTTP URL The Product Discount application in Chrome What happens if you omit parts of a URL If you omit the protocol, the default of http:// will be used. If you omit the filename, one of the default filenames for the Apache web server will be used: index.htm, index.html, or index.php. If you omit the filename and there is no default file, Apache will display an index of the files and directories in the path. 2017, Mike Murach & Associates, Inc. C1, Slide 37 2017, Mike Murach & Associates, Inc. C1, Slide 40 Requesting pages from an Internet web server A request for a specific page http://www.murach.com/shop-books/all/index.php A request for the default (home) page of a website http://www.murach.com/ Requesting applications from a local web server A request for the default page in an application directory http://localhost/book_apps/ch01_product_discount/ A request for a directory with no default page http://localhost/book_apps/ An error displayed in Chrome 2017, Mike Murach & Associates, Inc. C1, Slide 38 2017, Mike Murach & Associates, Inc. C1, Slide 41 An index of the apps in the book_apps directory How to test a PHP page for the first time 1. Make sure the Apache and MySQL servers are running. 2. Start a web browser and enter the URL for the application as shown in the last figure. 3. Test the page by entering both valid and invalid data, clicking on all links, and so on. How to retest a PHP page after changes Click the Reload or Refresh button in the browser. 2017, Mike Murach & Associates, Inc. C1, Slide 39 2017, Mike Murach & Associates, Inc. C1, Slide 42 7

The source code for a PHP page How to work with NetBeans projects To open a project, use the Open Project button in the toolbar. To start a new project, use the New Project button in the toolbar. To close a project, right-click on the project in the Projects tab and select the Close command from the resulting menu. How to work with files To open a file, use the Projects tab to navigate to the file and double-click the file. To start a new file, select the project and click the New File button in the toolbar. 2017, Mike Murach & Associates, Inc. C1, Slide 43 2017, Mike Murach & Associates, Inc. C1, Slide 46 How to view the source code for a page in Chrome and Firefox Right-click the page, then select the ViewPage Source command. How to view the source code for a page in IE and Edge Right-click on the page, then select the View Source command. Note about Microsoft Edge The View Source command isn t available by default for this browser. To enable it, you can press F12 to display the Developer Tools. Then, when you select the View Source command, the source code will be displayed in the Debugger tab within the Developer Tools window. About NetBeans NetBeans is an Integrated Development Environment (IDE) for developing PHP applications. NetBeans can make it easier to create, edit, and test the HTML, CSS, and PHP files that you need for a web application. About NetBeans projects A NetBeans project consists of a top-level directory that contains the subdirectories and files for an application. Netbeans adds an nbproject subdirectory that contains the extra files that NetBeans needs for managing the project. Mac OS X note To enable right-clicking with Mac OS X, you can edit the system preferences for the mouse. 2017, Mike Murach & Associates, Inc. C1, Slide 44 2017, Mike Murach & Associates, Inc. C1, Slide 47 NetBeans with three files in a project open Auto-completion and error marking in NetBeans 2017, Mike Murach & Associates, Inc. C1, Slide 45 2017, Mike Murach & Associates, Inc. C1, Slide 48 8

How to edit a PHP file with NetBeans Use normal editing techniques as you enter PHP code. When you see an auto-completion list, you can highlight an entry and press the Enter key to enter it into your code or you can double-click on it. If you see a red error icon at the start of a line that you have entered, you should fix whatever errors the line contains before you test the application. How to test a PHP application with NetBeans To run the current project, click on the Run Project button in the toolbar or press F6. To run other projects, right-click on the project and select the Run command. To run a file, right-click on the file and select the Run command. How to check the run configuration for a project Right-click on a project in the Projects tab and select the Properties command. Then, click on Run Configuration in the Categories list and check the Project URL. How to import a project Use the New Project command, but select PHP Application with Existing Sources in the Projects list. This will step you through the import procedure. In the third step, you are asked to check the run configuration. Here, you need to make sure the URL for running the project is correct. 2017, Mike Murach & Associates, Inc. C1, Slide 49 2017, Mike Murach & Associates, Inc. C1, Slide 52 The dialog box for starting a new project 2017, Mike Murach & Associates, Inc. C1, Slide 50 The dialog box for configuring a project 2017, Mike Murach & Associates, Inc. C1, Slide 51 9