Enter your Sign on user name and password.

Forgot password?
Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!

Use Chrome browser to play professor video
Matthew M.

Matthew M.

Web Application Development

Slide Duration:

Table of Contents

Course Introduction

12m 13s

Intro
0:00
What Is PHP?
0:12
PHP Hypertext Preprocessor
0:13
Why Learn PHP?
1:09
Why Learn PHP?
1:10
Web Application: Educator Store
2:25
Web Application: Educator Store
2:26
Example of Web Application
3:18
PHP in the Educator Store
7:12
Dynamic Content Generation
7:22
Ease of Website Maintenance
7:55
Form Input Processing and Access to Advanced Functionality
9:00
What You Will Learn
9:36
What You Will Learn
9:37
Who Is This Course For?
10:56
Who Is This Course For?
10:57
How PHP & The Web Work

15m 32s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Client-Server Model
0:53
Client-Server Model
0:54
HTTP Protocol
2:15
Definition of Protocol
2:16
Hypertext Transfer Protocol (HTTP)
2:37
Uniform Resource Locators
3:46
Uniform Resource Locators (URLs)
3:47
Form of URLs
4:13
Accessing Webpages with URLs
5:13
Serving Webpages
6:14
Serving Webpages, Client Machine, and Server Machine
6:15
Static vs. Dynamic Webpages
8:30
Static Webpage
8:31
Dynamic Webpage
8:55
Server-Side Scripting
9:54
Server-Side Scripting
9:55
Static and Dynamic Webpage Coding Example
11:17
Static and Dynamic Webpage Coding Example
11:18
Serving Dynamic Webpages
13:07
Serving Dynamic Webpages
13:08
Setting Up Your Development Environment

33m 11s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Development Environments
1:04
Development Environments
1:05
Our Default Development Environment: Window 7
1:54
Remote Development
4:04
Development Machine & Remote Server
4:05
Local Development
6:54
Development Machine
6:55
Software Used In This Course
9:41
Firefox Web Browser & Firebug Add-On
9:42
XAMPP
12:15
PSPAD Text Editor
13:16
XAMPP Installation
13:49
XAMPP Installation
13:50
Verify XAMPP Install
16:26
Verify XAMPP Install
16:27
localhost
19:08
localhost and 127.0.0.1 'loopback' IP Address
19:09
Document Root
21:16
Document Root and Directory Name
21:17
Document Root for Apache in XAMPP: htdocs & Example
22:13
Text Editor Spectrum
26:12
Text Editor Spectrum: Barebones to IDE
26:13
PSPad & Example
27:02
Finding Help
30:26
Web Resources
30:27
Homework Challenge
31:36
Homework Challenge
31:37
Homework Challenge (cont.)
32:38
Homework Challenge (cont.)
32:39
Your First PHP Script

12m 41s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
.php To HTML
1:00
.php To HTML
1:01
PHP Delimiters
2:20
PHP Delimiters: Opening & Closing PHP Tags
2:21
'Hello, World!' Example
4:34
Echo Statement & PHP Tags
4:35
Adding Second Heading
7:34
Homework Challenge
9:56
Homework Challenge
9:57
Basic PHP Syntax

40m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
PHP Delimiters
0:38
Long and Script Form
0:39
Short and ASP Style
1:33
Example
2:01
php.ini: PHP's Configuration
3:40
php.ini
3:41
Configuration Directives
3:48
Short and ASP Style: Enabled/Disabled
4:13
phpinfo()
7:58
Statements
14:28
PHP Statements
14:29
Example: PHP Statements
14:55
Comments
16:53
PHP Comments
16:55
Single-line Comments
17:37
Multi-line Comments
18:13
Example: PHP Comments
18:47
Coding Conventions
24:26
Coding Conventions
24:27
Example: PHP Coding Conventions
26:19
Homework Challenge #1
33:51
Homework Challenge #1
33:52
Homework Challenge #1 (cont.)
35:41
Homework Challenge #1 (cont.)
35:42
Homework Challenge #2
36:09
Homework Challenge #2
36:10
Homework Challenge #2 (cont.)
38:07
Homework Challenge #2 (cont.)
38:08
Variables & Numeric Data Types

16m 38s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:12
Working With Data
0:48
8 Types of Data for PHP
0:49
Identifiers
1:40
Identifiers: Definition and Example
1:41
Variables
2:47
Variables Definition
2:48
Variables Syntax
3:06
Integer Data Type
4:44
Integer Data Type
4:45
Integer Literals
5:08
Examples
5:30
Float Data Type
6:26
Float Data Type
6:27
Float Literals
7:00
Example
7:21
Example: PHP Code Declaring Variables
8:06
Example: PHP Code Declaring Variables
8:07
var_dump() Function
9:59
var_dump()
10:00
Example: Code and Output
10:30
Example: var_dump() Function
11:19
Coding Conventions: Variables
12:32
Lower Camel Case Notation
12:33
Variable Name Lengths
13:54
Homework Challenge
14:54
Homework Challenge
14:55
String Data Type

18m 6s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
String Data Type
0:29
String Data Type
0:30
Specifying String Literals
1:03
Single-Quoted Strings
1:53
Single-Quoted Strings
1:54
Escape Sequences
2:31
Escape Sequences
2:32
Example
2:46
Escape Sequences for Commonly Used Special Characters
4:32
Double-Quoted Strings
6:04
Double-Quoted Strings
6:05
Variable Interpolation
6:44
Coding Conventions: Strings
7:54
Coding Conventions: Strings
7:55
Homework Challenge
8:54
Homework Challenge
8:55
Include Files & Web Application Introduction

38m 43s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
include Statement
0:47
include Statement: Definition
0:48
Include Statement: Syntax
2:05
include Statement: Example
2:25
include Path
6:32
Absolute and Relative Path
6:34
Specified Path
7:15
Not Specified Path
7:55
Code Reuse
9:35
Code Reuse
9:36
Example
11:11
require Statement
12:56
require Statement: Definition
12:57
require Statement: Syntax
13:32
Include versus Require
13:52
Coding Conventions
16:33
Coding Conventions
16:34
Introduction to Our Web Application
20:32
Introduction to Our Web Application
20:33
Updating Web Application
21:14
Web Application Example
22:59
Homework Challenge
35:33
Homework Challenge
35:34
Homework Challenge (cont.)
37:38
Homework Challenge (cont.)
37:39
Arrays

34m

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is an Array?
0:42
What is an Array?
0:43
Arrays in PHP
1:44
Keys and Values
2:15
Types of Arrays
3:37
Indexed Arrays & Associative Arrays
3:38
array() Construct
6:47
Declaring Arrays
6:48
Defining Indexed Array
7:00
Defining Associative Arrays
7:43
Square Bracket Syntax
8:50
Square Bracket Syntax
8:51
Accessing Indexed Arrays
9:02
Accessing Associative Arrays
9:56
Arrays Example
10:41
Indexed Arrays Example
10:45
Associative Arrays Example
13:55
Multi-Dimensional Arrays
18:28
Multi-Dimensional Arrays
18:29
Multi-Dimensional Arrays Example
18:51
Multi-Dimensional Arrays in PHP File
20:34
Coding Conventions: Arrays
27:59
Coding Conventions: Arrays
28:00
Homework Challenge #1
29:20
Homework Challenge #1
29:21
Homework Challenge #2
30:38
Homework Challenge #2
30:39
Web Application Development

27m 38s

Intro
0:00
Versions
0:14
Version 3.0
1:23
Version 3.1
8:08
Version 3.2
11:42
Version 3.3
20:27
Homework Challenge
26:31
Homework Challenge
26:32
Script Input & The GET Method

30m 18s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Providing Input to PHP
0:39
GET Method, POST Method, and Cookies
0:40
Name/Value Pairs
1:22
GET Method
1:57
HTTP GET Method
1:58
Query String
2:52
GET Method Example
3:38
GET Method Example
3:39
Review of HTML Forms
8:16
HTML Forms
8:17
Input Control and Submitted Form
9:13
<form> Tag
10:07
<form> Tag
10:08
Method
10:34
Action
11:13
Input Control Examples
11:50
Input Control Examples
11:51
Common Input Controls
17:31
Common Input Controls
17:32
Query Strings
18:52
Query Strings
18:53
Query Strings Syntax
19:12
URL Encoding
20:01
URL Syntax
20:02
Examples
21:17
Simple Form Example
22:28
urlencode() Function
24:08
urlencode() Function
24:09
Example
25:03
urlEncoding Text Example
25:54
Simple Form Example
25:55
Homework Challenge
28:46
Homework Challenge
28:47
Accessing Form Data in PHP

32m 1s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
$_GET Array
0:48
$_GET Array
0:49
Accessing the Value of a Name/Value Pair Submitted Via GET
1:04
Name Form Example
2:54
Name Form and the $_GET Array
2:55
Using Arrays with Input Controls
6:34
Using Arrays with Input Controls
6:35
Common Example
6:47
Indexed Array Form Example
8:16
Indexed Array Form Example
8:17
Associative Arrays with Input Controls
10:14
Associative Arrays with Input Controls
10:15
Associative Arrays Example
11:41
Associative Arrays Example
11:42
Echo Form Example
15:18
Echo Form Example
15:19
Outputting Arrays In String
23:42
Variable Interpolation
23:43
Outputting a Value in an Indexed Array Within a String
24:12
Simple' Syntax, 'Complex' Syntax, and 'Curly Brace' Syntax
25:00
Outputting Arrays In String Example
26:25
Outputting Arrays In String Example
26:26
Homework Challenge
29:39
Homework Challenge
29:40
Web Application Development

20m 20s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
Version 3.3
0:38
Version 3.3
0:42
Version 4.0 Changelog
2:43
GET Query
2:45
Adding, Editing, and Removing
3:24
Version 4.0 Coding Example
3:55
item.php, itemID, and itemListing
4:00
Version 4.1 Changelog
10:36
Version 4.1 Changelog
10:37
Version 4.1 Coding Example
11:45
Adding Checkout and Thank You & Editing Footer and Store
11:46
Homework Challenge
18:45
Homework Challenge
18:46
Expression & Operators

31m 56s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Expressions
0:41
Expressions Definition
0:42
Example: Literals
0:55
Example: Variables
1:05
Operators
1:44
Operators Definition
1:45
Unary, Binary, and Ternary Operators
2:07
Assignment Operators
2:52
Assignment Operators
2:53
Array Assignment Operator
3:47
Arithmetic Operators
6:15
Operators for Common Arithmetic Operations
6:16
Modulus Operator
7:41
Arithmetic Operators Example
8:25
Increment/Decrement Operators
10:48
Increment/Decrement Operators
10:49
Pre- and Post- Increment/Decrement
12:43
Coding Example
15:14
Combined Assignment Operators
16:44
Combined Assignment Operators
16:45
Combined Assignment Operators Examples
18:23
Coding Example
19:39
String Operators
20:28
Concatenation Operator, String Variables, and String Literals
20:29
String Operators Example
22:41
Precedence & Associativity
23:40
Precedence & Associativity
23:41
Expression Containing Multiple Operations
23:58
Expression Containing Two Operations of Equal Precedence
25:55
Using Parentheses to Force Precedence
26:52
Precedence & Associativity Review
28:57
Homework Challenge
31:08
Homework Challenge
31:09
Web Application Development

20m 51s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Version 4.1 Review
0:33
Version 4.1 Review
0:34
Version 5.0 Changelog
1:05
Version 5.0 Changelog
1:06
Version 5.0 Example
2:19
Adding View Cart & Editing Checkout, Footer and Store
2:20
Version 5.1 Changelog
15:36
Version 5.1 Changelog
15:37
Version 5.1 Coding Example
17:33
Forwarding Order Total to Thank You Page
17:34
Homework Challenge
20:09
Homework Challenge
20:10
Boolean & Null Data Types

20m 11s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Boolean Data Type
0:38
Boolean Data Type
0:39
Two Boolean Literals
1:24
Boolean Example
1:50
Boolean Example
1:51
Comparison Operators
4:00
Comparison Operators Definition
4:01
Common Comparison Operators
4:40
Comparison Operators Example
6:49
Comparison Operators (Cont.)
10:10
Identical and Not Identical
10:11
Example: Identical and Not Identical
11:24
Null Data Type
13:36
Null Data Type Definition
13:37
Null Literal
14:08
Variable and Null Data Type
14:30
'==' Operator
15:24
Null Data Type Example
15:59
Coding Convention
18:41
Coding Convention
18:42
Homework Challenge
19:17
Homework Challenge
19:18
Type Casting

22m 41s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Type Juggling
0:54
Type Juggling
0:55
Automatic Conversion
2:23
Type Casting
3:53
Type Casting
3:54
Implicit and Explicit Type Casting
4:00
Explicitly 'cast' a Variable Example
4:16
Type Casting (cont.)
6:48
PHP Allows the Following Explicit Type Casts
6:49
The settype () Function
8:18
Type Casting Coding Example
9:00
Explicit Type Casts
9:01
String Conversions
14:52
String Conversions
15:05
Common Conversions to String
15:55
Numeric Conversions
18:18
Numeric Conversions
18:19
Boolean Conversions
20:29
Boolean Conversions
20:30
Homework Challenge
21:38
Homework Challenge
21:39
Introduction to Functions

52m 20s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
What are Functions?
0:51
Definition of Faction
0:52
PHP and Function Call
1:53
Function Calls
2:42
Function Calls
2:43
Function Arguments
3:17
Return Values
4:56
Return Values
4:57
Function Chaining
6:29
Function Chaining
6:30
PHP.net Function Reference
8:23
PHP.net & Function Prototypes
8:24
PHP.net Function Reference Example
9:29
Optional Function Arguments
12:28
Optional Function Arguments
12:29
String Functions
14:57
strtoupper() and strtolower()
14:58
implode (), str_replace(), explode(), strpos(), substr(), and strlen()
18:31
Array Functions
25:48
count()
25:49
in_array() and array_key_exists()
26:06
sort() and ksort()
26:37
Example: count() and in_array()
27:50
Example: array_key_exists()
29:53
Example: sort() and ksort()
31:20
Date & Time Functions
33:38
date() and time()
33:39
getdate()
34:49
mktime()
35:01
Date & Time Functions
35:12
Example: date() and time()
35:58
Example: getdate()
42:15
Example: mktime()
43:15
Homework Challenge #1
44:31
Homework Challenge #1
44:32
Homework Challenge #1 (Cont.)
45:28
Homework Challenge #1 (Cont.)
45:29
Homework Challenge #2
46:34
Homework Challenge #2
46:34
Homework Challenge #2 (Cont.)
48:06
Homework Challenge #2 (Cont.)
48:07
Homework Challenge #2 (Cont.)
49:17
Homework Challenge #2 (Cont.)
49:18
Homework Challenge #3
50:08
Homework Challenge #3
50:09
Constants

19m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Constants vs. Variables
0:55
Constants vs. Variables
0:56
Constant Identifiers
2:28
Constant Identifiers Definition and Examples
2:29
Declaring Constants
3:47
Two Ways of Declaring Constants
3:48
Syntaxes
4:10
Major Difference in the Two Forms
4:48
Using Constants Example
6:25
Using Constants Example
6:26
Coding Conventions
11:08
Constant Names
11:09
define () Function
11:42
Meaningful Names
12:00
$_SERVER Superglobal
12:23
$_SERVER
12:24
$_SERVER ['DOCUMENT_ROOT']
13:15
$_SERVER Superglobal Example
13:52
Homework Challenge
17:40
Homework Challenge
17:41
Web Application Development

26m 29s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 6.0
1:13
Version 6.0 & Version 5.1 Review
1:14
Version 6.0 Changelog
11:24
Version 6.0 Changelog
11:25
Version 6.1 Changelog
12:00
Version 6.1 Changelog
12:01
Version 6.1 Coding Example
12:42
Version 6.1 Coding Example
12:43
Version 6.2 Changelog
15:18
Version 6.2 Changelog
15:19
Version 6.2 Coding Example
18:19
Version 6.2 Coding Example
18:20
Homework Challenge
25:24
Homework Challenge
25:25
Conditional Control Structures

18m 58s

Intro
0:00
Lesson Overview
0:26
Lesson Overview
0:27
Statement Groups
0:57
Statement Groups
0:58
Example
1:10
Conditional Control Structures
1:38
Conditional Control Structures
1:39
PHP Control Structures
1:56
if Statement
2:32
if Statement
2:33
if Statement (cont.)
3:49
if Statement Coding Example
3:50
else Statement
7:26
else Statement
7:27
if/else Statement Coding Example
8:50
isset() Construct
9:59
isset() Construct
10:00
isset() Construct Coding Example
12:00
Coding Conventions
15:13
Coding Conventions
15:14
Coding Conventions (Cont.)
16:39
Coding Conventions (Cont.)
16:40
Homework Challenge
17:25
Homework Challenge
17:26
Error Handling

19m 8s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Error Handling in PHP
0:41
Error Handling in PHP
0:42
Coding Example
1:45
error_reporting() Function
7:02
error_reporting() Function
7:03
Coding Example
8:04
Additional Error Directives
9:02
display_errors
9:13
log_errors
9:37
error_log
9:50
track_errors
10:12
Coding Examples
10:29
Error Control Operator
13:38
Error Control Operator & Coding Example
13:39
Homework Challenge
16:19
Homework Challenge
16:20
Homework Challenge (cont.)
17:58
Homework Challenge (cont.)
17:59
Logical & Ternary Operators

23m 22s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
Logical Operators
0:49
Logical Operators Definition
0:50
NOT (!)
1:08
OR ( ||, or)
1:35
AND (&&, and)
2:08
XOR (xor)
2:30
Logical Operators (cont.)
2:54
The OR and AND Logical Operators
2:55
Precedence of Logical Operators
3:35
Logical Operators Coding Example
3:58
Logical Operators Coding Example
3:59
Short-Circuit Operators
9:54
Short-Circuit Operators
9:55
Coding Example
10:49
Ternary Operator
14:07
Ternary Operator
14:08
Syntax and Example
14:24
Coding Conventions
17:36
Coding Conventions
17:37
Homework Challenge
19:08
Homework Challenge
19:09
Homework Challenge (cont.)
20:26
Homework Challenge (cont.)
20:27
Web Application Development

19m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 6.2 Review
0:26
Version 6.2 Review
0:27
Version 7.0 Changelog
2:39
Version 7.0 Changelog
2:40
Version 7.0 Coding Example
4:35
Version 7.0 Coding Example
4:36
Version 7.1 Changelog
12:43
Version 7.1 Changelog
12:44
Version 7.1 Coding Example
13:52
Version 7.1 Coding Example
13:53
Homework Challenge
17:42
Homework Challenge
17:43
More Conditional Control Structure

20m 49s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
elseif Statement
0:45
elseif Statement
0:46
elseif Statement Coding Example
1:22
Multiple elseif Statements
2:16
Multiple elseif Statements
2:17
Multiple elseif Statements Coding Example
3:07
Adding an else Statement
5:44
Adding an else Statement Overview
5:45
Adding an else Statement Coding Example
6:50
switch() Statement
8:07
switch() Statement
8:08
switch() Statement (Cont.)
9:14
switch() Statement (Cont.)
9:15
switch() Statement Coding Example
11:09
default Case
14:20
default Case
14:21
default Case Coding Example
15:13
Coding Conventions
15:57
Coding Conventions
15:58
Coding Conventions (cont.)
17:10
Coding Conventions (cont.)
17:11
Homework Challenge
18:06
Homework Challenge
18:07
Homework Challenge (cont.)
19:18
Homework Challenge (cont.)
19:19
Nested Conditional Control Structures

24m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Nested Control Structures
0:36
Nested Control Structures
0:37
Nested Control Structures Coding Example
2:08
Coding Conventions
6:34
Nested vs. Not Nested Control Structures
6:35
Debugging Control Structures
7:51
Debugging Control Structures
7:52
Incorrectly Specified Test Conditions and Forgetting a Break Statement
8:32
Incorrectly Placing an Opening or Closing Curly Brace
12:14
Debugging Tips
16:24
Tracing the Execution of Your Code
16:25
Adding Echo Statement
17:15
Homework Challenge
21:41
Homework Challenge
21:42
Homework Challenge (cont.)
23:08
Homework Challenge (cont.)
23:09
Web Application Development

28m 20s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 7.1 Review
0:46
Version 7.1 Review
0:47
empty () Construct
1:38
empty () Construct
1:39
empty () Construct Coding Example
2:37
Version 8.0
5:32
Version 8.0 Overview
5:33
Version 8.0 Coding Example
7:08
Version 8.0 Coding Example
7:09
Version 8.1
16:13
Version 8.1 Overview
16:14
Version 8.1 Coding Example
19:48
Version 8.1 Coding Example
19:49
Homework Challenge
26:19
Homework Challenge
26:20
Sending Email Using PHP

43m 50s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
Built-in Mail Extension
1:28
Built-in Mail Extension
1:29
SMTP Overview
2:04
SMTP Overview
2:05
SMTP - Windows
3:08
SMTP - Windows
3:09
SMTP - Linux/UNIX
4:58
SMTP - Linux/UNIX
4:59
Mail Configuration Directives
6:35
Mail Configuration Directives
6:36
Coding Example
7:48
Mail Server Authentication
10:20
Mail Server Authentication
10:21
fake sendmail Program
12:27
fake sendmail for Windows
12:28
Main 'add-on' feature
13:03
Username & Password
13:25
SMTP - XAMPP for Windows
14:07
SMTP - XAMPP for Windows
14:08
Sendmail Example
16:19
Sendmail Example
16:20
mail() Function
18:39
mail() Function
18:40
additional_headers
19:45
'From' Header
20:12
mail() Function Coding Example
21:09
mail() Function Coding Example
21:40
Web Application Development
31:43
Version 9.0 Changelog
31:44
ContactUs.php
32:52
ContactUs.php
32:53
contactInfo
33:45
Version 9.0 Coding Example
34:31
Version 9.0 Coding Example
34:32
Homework Challenge
41:32
Homework Challenge
41:33
User-Defined Functions

56m

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Defining Functions
1:29
Four Parts of Defining a Function
1:30
Functions Example 1
2:29
Function Parameters
5:29
Function Parameters
5:30
Functions Example 2
8:20
Return Statements
12:53
Return Statements
12:54
Functions Example 3
14:20
Where to Define Functions
20:34
Where to Define Functions
20:35
include_once Construct
22:10
include_once Construct
22:11
include_once Coding Example
23:55
Reasons to Use Functions
27:44
Take Advantage of Code Reuse
27:45
Improve Code Readability
29:56
Use Instead of 'content' Include Files
32:12
Web Application Development
34:42
Version 10.0 Changelog
34:43
Version 10.0 Coding Example
37:55
Version 10.0 Coding Example
37:56
Outputting HTML in Functions
47:04
Outputting HTML in Functions
47:05
Example
49:02
Coding Conventions
53:16
Coding Conventions
53:17
Homework Challenge
54:33
Homework Challenge
54:34
Variable Scope

31m 37s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is Variable Scope?
0:57
Variable Scope
0:58
Global Scope
1:15
Local Function Scope
1:50
Variable Scope Coding Example
2:26
Variable Scope Coding Example
2:27
global Keyword
8:52
global Keyword Overview
8:53
global Keyword Example
9:25
Superglobals
12:34
Superglobals
12:35
Superglobals Example
14:53
Pitfalls of Global Variables
18:34
Pitfalls of Global Variables
18:35
When to Define Variables
22:09
When to Define Variables
22:10
Putting It All Together
22:56
Putting It All Together Example
22:57
Function Scope
28:56
Function Scope
28:57
Homework Challenge
29:41
Homework Challenge
29:42
Homework Challenge (cont.)
30:59
Homework Challenge (cont.)
31:00
Web Application Development

28m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 11.0 Changelog
0:56
Version 11.0 Changelog
0:57
processGetVar()
1:42
processGetVar() Overview
1:43
processGetVar() Example
2:25
emailComments()
6:35
emailComments() Overview
6:36
emailComments() Example
7:14
outputItemLink()
11:19
outputItemLink() Overview
11:20
outputItemLink() Example
11:45
calcCartTotal()
19:25
calcCartTotal() Overview
19:26
calcCartTotal() Example
21:14
Homework Challenge
25:56
Homework Challenge
25:57
Optional Parameters

19m 35s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Optional Parameters
0:26
Optional Parameters Definition
0:27
Default Values
0:53
Optional Parameters Coding Example
3:26
More on Optional Parameters
6:55
Multiple Optional Parameters
6:56
Coding Example
8:05
Homework Challenge
16:18
Homework Challenge
16:19
Web Application Development

23m 7s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 12.0 Changelog
0:55
Version 12.0 Changelog
0:56
Update to outputLink()
1:44
Update to outputLink()
1:45
outputLink() Coding Example
2:40
outputImg()
13:57
outputImg() Overview
13:58
outputImg() Coding Example
15:35
Homework Challenge
22:05
Homework Challenge
22:06
Introduction to Conditional Loops

57m 20s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
while Loop
0:48
Definition
0:49
Syntax and Usage
1:12
Coding Example
3:33
Looping Over Arrays
13:16
Looping Over Arrays
13:17
Coding Example
13:53
Looping Over Arrays (cont.)
16:43
Internal Array Pointer
16:44
Array Traversal Functions
17:29
current ()
17:30
next () and prev ()
18:16
reset () and end ()
19:25
key ()
19:40
Indexed Arrays: Using current () and next ()
20:40
Indexed Arrays: Using current () and next ()
20:41
Associative Arrays: Using key (), current (), and next ()
24:06
Associative Arrays: Using key (), current (), and next ()
24:07
Array Traversal Functions (cont.)
29:41
list () Construct and Example
30:07
each () Construct and Example
34:40
Lopping Over Arrays Using list(), each()
42:13
Lopping Over Arrays Using list(), each()
42:14
Control Structure Scope
50:37
Definition and Example
50:38
Control Structure Scope Coding Example
51:59
Coding Conventions
54:20
Coding Conventions
54:21
Homework Challenge
54:58
Homework Challenge
54:49
More on Conditional Loops

35m 50s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
do-while Loop
0:42
do-while Loop
0:43
Simple do-while Loop Example
1:51
Another do-while Loop Example
4:09
continue Statement
10:46
continue Statement
10:47
For Example
11:07
continue Statement Coding Example
12:44
break Statement Re-Visited
18:10
break Statement Re-Visited
18:11
break Statement In while Loops Example
19:38
Infinite Loops
23:26
Infinite Loops
23:27
Coding Example
24:57
Common Loop Pitfalls
25:59
Counter Initialization Occurs in Loop
26:30
Counter Not Incremented in Loop
29:30
Unreachable Break Statement
30:50
Coding Conventions
33:48
Do-while Statements Coding Conventions
33:49
Homework Challenge
34:28
Homework Challenge
34:29
Web Application Development

22m 7s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 13.0 Changelog
0:48
Updating 'viewCart.php' and calcCartTotal()
0:49
Creating isValidCart()
9:22
Adding Three New Item to the Store & Links
15:56
Version 13.1 Changelog
17:20
Updating outputItemLink() to Remove Its Global Dependency on $itemCatalog
17:21
Homework Challenge
20:34
Homework Challenge
20:35
For & Foreach Loops

29m 28s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
for Loops
0:45
for Loops
0:46
Expression 1
1:22
Expression 2
1:47
Expression 3
2:01
Simple Example
2:27
Simple Example
2:28
Notes on for Loops
8:56
Notes on for Loops
8:57
Ending Loop Using Test Condition and Break Statement
10:06
Ending Loop Using Test Condition and Break Statement
10:07
foreach Loops
12:03
foreach Loops
12:04
Indexed Array Syntax
14:10
Syntax
14:11
Example
15:23
Associative Array Syntax
18:31
Syntax
18:32
Example
19:47
Coding Conventions
25:05
for Loops
25:06
foreach Loops
25:58
Homework Challenge
26:52
Homework Challenge
26:53
Web Application Development

25m 58s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 14.0 Changelog
1:19
Version 14.0 Changelog
1:20
Version 14.0 Coding Example
1:57
Version 14.0 Coding Example
1:59
Version 14.1 Changelog
5:39
Version 14.1 Changelog
5:40
Version 14.1 Coding Example
7:06
Version 14.1 Coding Example
7:07
Version 14.2 Changelog
15:37
Version 14.2 Changelog
15:38
Version 14.2 Coding Example
16:25
Version 14.2 Coding Example
16:26
Homework Challenge
23:35
Homework Challenge
23:36
Conditional Loop Wrap-Up

23m 12s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Nested Conditional Loops
0:39
Nested Conditional Loops
0:40
Coding Example
1:10
continue & break Re-Visited
5:17
Continue Statements and Coding Example
5:30
Break Statements and Coding Example
11:34
Loop Debugging Tips
15:16
Add Short Debug Statement At the Very Beginning
15:17
Output a Counter Variable
18:10
Add Debug Statement At the Very End
19:20
Homework Challenge
20:20
Homework Challenge
20:21
Homework Challenge (cont.)
22:00
Homework Challenge (cont.)
22:01
Variable-Length Parameter Lists

22m 16s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Variable-Length Parameter Lists
0:34
Variable-Length Parameter Lists
0:35
Coding Example
1:51
Variable-Length Parameter Lists (cont.)
5:21
When a Parameter List is Defined For the Functions
5:22
Coding Example
6:32
Variable Type Functions
9:54
is_int (), is_float (), is_string (), and is_bool()
9:55
is_ array ()
10:50
is_null ()
11:01
Variable Type Functions Coding Example 1
11:27
is_numeric() and Example
15:57
Variable Type Functions Coding Example 2
17:12
Homework Challenge
19:35
Homework Challenge
19:36
Homework Challenge (cont.)
20:52
Homework Challenge (cont.)
20:53
Web Application Development

38m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 15.0 Changelog
0:33
outputLink (), outputImg (), is_array () and is_string ()
0:34
Version 15.0 Coding Example
1:31
Version 15.0 Coding Example
1:32
Version 15.1 Changelog
7:55
Removing Redundant Code and Adding New Function Called outputHtmlTag ()
7:56
Version 15.1 Coding Example
8:37
Version 15.1 Coding Example
8:38
Version 16.0 Changelog
14:55
Creating emailOrder() Using New Constants ORDER_EMAIL_FROM and ORDER_EMAIL_SUBJECT
14:56
Version 16.0 Coding Example
16:30
Version 16.0 Coding Example
16:31
Version 16.1 Changelog
32:21
Creating formatAsDollars ()
32:22
Version 16.1 Coding Example
32:57
Version 16.1 Coding Example
32:58
Homework Challenge
36:27
Homework Challenge
36:28
Miscellaneous Topics

31m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
register_globals Directive
0:58
register_globals
0:59
Coding Example
2:04
$_GET vs. $HTTP_GET_VARS
4:07
$_GET vs. $HTTP_GET_VARS
4:08
register_long_arrays Directive Coding Example
5:44
Magic Constants
7:30
Magic Constants
7:31
__LINE__, __FILE__, __FIR__, and __FUNCTION__
8:16
Coding Example
9:06
exist() & die()
13:19
exist() & die()
13:20
Coding Example
14:08
Execution Operator
16:23
Execution Operator
16:24
Coding Example
17:27
Array Operators
18:23
Equality (==) and Inequality (!=, <>)
18:43
Identity (===) and Non-Identity (!==)
19:13
Union (+) Operator
19:41
Array Operators Coding Example
20:07
Variable Variables
24:13
Variable Variables
24:14
Coding Example
26:07
Variable Functions
28:02
Variable Functions
28:03
Coding Example
29:13
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to PHP
  • Discussion

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for Educator.com

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.
  • Learn at your own pace... anytime, anywhere!

Web Application Development

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:10
    • Lesson Overview
  • Version 15.0 Changelog 0:33
    • outputLink (), outputImg (), is_array () and is_string ()
  • Version 15.0 Coding Example 1:31
    • Version 15.0 Coding Example
  • Version 15.1 Changelog 7:55
    • Removing Redundant Code and Adding New Function Called outputHtmlTag ()
  • Version 15.1 Coding Example 8:37
    • Version 15.1 Coding Example
  • Version 16.0 Changelog 14:55
    • Creating emailOrder() Using New Constants ORDER_EMAIL_FROM and ORDER_EMAIL_SUBJECT
  • Version 16.0 Coding Example 16:30
    • Version 16.0 Coding Example
  • Version 16.1 Changelog 32:21
    • Creating formatAsDollars ()
  • Version 16.1 Coding Example 32:57
    • Version 16.1 Coding Example
  • Homework Challenge 36:27
    • Homework Challenge

Transcription: Web Application Development

Hello again, and welcome back to Educator.com's Introduction to PHP course.0000

In today's lesson, we are going to be going over our final updates to our store web application.0005

In the lesson, we are going to have four different updates to the store: 15, 15.1, and 16.0 and 16.1.0011

What we are going to do is incorporate some of the material we learned in our lecture on variable-length parameter lists,0022

and then also just add some additional features that are going to improve our web application.0028

In version 15.0, what we are going to do is update the outputLink and outputImage functions we have in the outputLIB.php, our output function library.0035

Currently, these functions take in several different attributes, and they each have two optional attributes: one for ID and one for class.0047

which, you will remember, is so that a user calling these functions can optionally provide0054

the HTML ID or class attribute to use for CSS or Javascript operations.0060

What we are going to do is replace those optional attributes with a single optional attribute, which is going to accept an array.0065

And in that array, it is going to allow name/value pairs so a user can set any sort of options they want for a particular tag.0072

In this case, it would be the image and the a tag.0081

We are going to make use of the new functions we learned about called is_array and is_string to perform some input validation.0085

Let's take a look at some of the code.0093

If we look at the last version of outputLIB.php, which is version 14.2, here we can see that the outputImg function, for example,0095

takes in three parameters: the name of the image file and the two optional parameters0106

for the ID and class attributes that we can optionally specify for the image tag.0110

Additionally, if we look down at outputLink, we can see, it takes four parameters: two required ones (one for the URL of the link,0117

one for the body of the link), and then it also has the same optional parameters (ID and class),0125

again, to provide those ID and class attributes to the a tag, if we desire.0129

Well, in our new versions, let's take a look at outputImg first.0136

What we have done is replaced the ID and class optional parameters with a single parameter called attributes.0142

And what attributes is: it is an associative array that is going to contain name/value pairs0149

that allow a user to set any HMTL attribute pairs for the image tag that they desire.0156

So, they can do class and ID, just as before; but they can also add other parameters, as well, such as maybe the image size, width, or height.0161

The way the file changes is: we start similarly by creating the image tag and setting the source attribute to the location of the image file.0171

But then, things change a little bit: if we look at the old version, what we did is tested to see if the ID or class parameters were empty.0182

And if they weren't empty, then we went ahead and appended the ID attribute, along with the provided value, to the image tag.0190

And we did the same thing for class.0198

What we do in the new version is: we make use of a foreach loop to loop over an attribute's array that the user can optionally provide.0201

And what we do is: for any attribute name/value pair that the user provides in this associative array, we add that to the image tag,0209

so they can still the ID attribute; they can still add the class attribute.0217

A couple things to notice: the input validation function, or test--we tested the attributes array that they provided.0222

It is not empty, which means that it is not an empty array.0229

And then, we also test to make sure that it is an array, because when we loop over it, we want to loop over an array.0233

This makes use of this new is_array function that we learned about, that tells us about data types.0238

If it is an array, and if it is not empty, then we loop over the attributes array.0243

And then, we also perform tests on each name/value pair provided.0249

Name/value pairs in HTML attributes are both strings, so we test that, for each element of this associative array attributes,0253

that an attribute name exists and an attribute value exists, which are the key and the values of that array,0262

and then, also that each of them is a string; and we make use of the is_string function that we learned about in the last lesson0268

that tells us if the data type is string.0275

If they are both provided and if they are both strings, then we go ahead and add that attribute name and value to the image tag.0278

And so, what these functions do is: it allows us to perform some more intense input validation,0287

to make sure that we are only performing the function on acceptable inputs.0292

Now, if we go down and look at the outputLink function, we have done the same thing.0297

We have replaced the ID and class optional parameters with the attributes parameter.0304

And we basically have the same code here that we did in the outputImg function.0311

The only difference is that we create an a tag, or a link tag; we append the URL provided by the user.0316

We go ahead and use the same functionality to test attributes, to make sure it is an array,0324

to make sure it is not empty, to make sure that any name/value pairs provided are strings...0328

And we add those attributes to this a tag, and then we close the a tag and output the body that the user provides from the second parameter.0332

And we can see these new functions being used in two different spots.0343

For example, if we go to outputItemLink, which is our function that outputs on a shopping cart or the department home page,0347

a link to an item's page that contains a small image of the item, and a link that is the item's name,0354

we can see that in that function, we use outputLink twice.0362

And the second time that we use outputLink, we had been specifying the class attribute for the itemID link.0366

If we look at the old version of itemLink, the last version, we can see that we have used the old syntax for calling this outputLink function,0376

where we provided a null value for the ID, because as we know, with optional parameter, if you provide a second optional parameter,0384

you also have to provide a value for the first one.0393

So, we provided null for the ID, and then we provided itemLink as the class.0394

And then, in our new version, we replaced those two parameters with a single parameter that is an array,0401

that contains the attribute name class, and then its value, itemLink.0407

And so, that is how we make use of that new outputLink function.0412

Additionally, on item.php, which is our page that shows the item's information, we use the outputImg function to output the item's image.0416

And the item image that we output...we include in that image tag the ID HTML attribute and set it to item image.0425

Now, in our previous version of item.php (for example, in 14.2), we can see that we specified two parameters to the outputImg function,0435

the first one being the url, or the image file, and the second one being the value of the ID attribute.0451

Well, in our new function, we can accept an array of HTML attributes.0458

Here, we have gone ahead and created an array that submits the ID attribute, set to the value itemImage.0463

And so, that is how we make use of those new outputImg and outputLink functions.0470

Now, what you may have noticed when we created these outputLink and outputImg functions is that they both contain a lot of redundant code.0478

And we know from our experience that any time we have redundant code, or code that is used over and over again,0486

we want to extract it and put it in one spot, and make use of it--for example, by creating a function that makes use of that code.0492

That is actually what we are going to do in version 15.1.0500

We are going to take the redundant code in both of those updated functions, and we are going to place it in a new function called outputHtmlTag.0502

And this new function is also going to make use of the is_array function and the is_string function that we had learned about in the last lesson.0510

So, if we go and take a look at the outputLIB for version 15.1, we can see, we have created a new function here called outputHtmlTag.0518

What it does is accepts one required and two optional parameters.0530

The required parameter is the tag name: for example, for an image tag, it would be the string img.0535

For a link or an anchor tag, it would be the letter a.0541

It also allows an optional parameter that is an attributes array, which is the same thing that we just created for our outputLink0545

and outputImg functions, where a user can call the function and pass in any HTML attribute name/value pairs it wishes to set.0554

for whichever tag this function is going to create.0563

Additionally, the user can optionally provide a body to the tag.0566

For example, in our image tags, we don't have a body to the image tag; but for our link tags, we have a body.0570

For example, the name of an item is in the body of the anchor tag, and that is what the user was able to click on to go to the link.0576

What we do is: we are dynamically creating this tag "on the fly."0584

Basically, this starts off creating the tag, and we create the tag with the name passed in in the value tag.0590

And then, we go through and add any attributes provided via this optional attributes parameter, and add those to the tag.0597

For example, for the a tag, what we do is: this attributes associative array is also going to include the attributes0607

that we hard-coded before (into the image tag and the anchor tag, for example).0617

For example, in the image tag, we always have a source attribute, and in the a tag, we always have an href attribute.0623

So now, what we do is: because we have created a generic HTML tag function, and href and source are both HTML attributes,0629

we add them to an attributes array that we pass to this new outputHtmlTag function.0637

And then, this outputHtmlTag function loops over these attributes, just like it did in the last versions we created0644

of outputImg and outputLink, and appends them to whatever tag it is dynamically creating.0651

Additionally, if the user provided a body, and the body is a string (because in HTML, the body has to be a string),0656

then we go ahead and add the body to the tag, and then create a closing tag after the body.0664

And if not, we just go ahead and close the tag without any body.0670

And then, we return the well-formed HTML tag.0674

So, if we go and look at outputImg, it has changed a lot from the last version.0678

In our last version, we started creating the image tag, building up a string that includes a source attribute, and so forth.0684

And then, we looped over all of the different attributes that we may want to pass into the function.0696

Well, now what we do is: we still allow this function to be passed a number of attributes to add to the image tag,0701

but then, what we also do is: we are adding an attribute to this attributes array.0710

And if the attributes array wasn't passed in (for example, the user didn't provide maybe an ID or a class attribute),0716

it goes ahead and creates that array, and adds the source attribute, which we always need for our image tag.0721

And we set it equal to the path to the image file, which uses the IMAGE_DIR constant and the image file parameter passed to the function.0726

Then, what we do is: using this attributes array, which contains any attributes that were already passed into the function,0736

along with the added source attribute, we pass that to the outputHtmlTag, and then include as the first argument to the tag the string Img.0741

And what that is going to say is "I want outputHtmlTag to create an image tag, and I want it to have all of the attributes0751

contained in this attributes array," which is going to always include the source attribute, as well as0758

any additional attributes a user provided that called this outputImg function.0763

Similarly, if we look down at the outputLink function, its content has been changed.0768

Before, this is what it looked like, where it started building up the a tag on its own, and then it looped over all of the different attributes0777

that were possibly provided to the function, and then it closes the link tag with the body.0788

Well, in the new version, what it does is: it accepts the same amount of parameters:0794

the URL, the body of the link, and also any attributes a user wishes to add to that a link.0800

And then, what it does is: similar to the new outputImg function, it adds to this attributes array the href HTML attribute and sets it equal to the URL value.0807

And because that is an attribute that we need to have in our anchor tag, so that the link will work,0818

we add it to this attributes array, and then we call outputHtmlTag.0823

With the first parameter, we provide the letter a, which is the name of the tag we want to create, which is an anchor or link tag.0829

We provide it the attributes array, which contains any attributes passed into this outputLink function,0834

as well as always providing the href attribute, along with its URL value.0840

And then, we also provide the body that was supplied to the outputLink function to the outputHtmlTag, because our links have a body to them.0844

And you will notice, there is a difference there and in outputImg.0853

And in outputImg, when we call the outputHtmlTag, we only passed it two parameters or two arguments,0857

because the image tag, in this case, doesn't have a body.0862

And so, that is how we have taken that redundant code that looped over the different attributes0868

that we could provide to an outputImg function or an outputLink function, and consolidated it into one file that we can use now.0873

We could use it to create any kind of HTML tag that we want, not just anchor tags or image tags.0881

We could use that in many different ways.0886

And so, that demonstrates how we can create a function that we can reuse in multiple spots.0890

In version 16.0, we are going to add some functionality--the last functionality we are going to add to the web application.0897

We are going to create a new function called emailOrder.0905

And what that is going to do is: when a user submits an order on checkout.php, after they have added items to their Shopping Cart0908

and then when they submit their shipping information, an email is going to be created that gets sent to the store administrator0915

that is going to contain the order's information (such as all the items that were in the order, the contact information,0923

the shipping information of the customer...), and it is also going to include an order timestamp that shows when the order was created.0930

And so, before, when an order was created, we simply output a message to the user.0937

This makes it a little more realistic in functionality, in that we could use this to email a store administrator to manually process an order.0942

And the order email contains information needed to do that.0950

In order to do this, we are going to be creating two new constants: ORDER_EMAIL_FROM and ORDER_EMAIL_SUBJECT, in config.php.0955

And we are going to use these constants in our emailOrder function to use in the mail function provided by PHP.0962

One other thing that we are going to do is: in checkout.php, in our current version, when we echo the user's shipping information0970

that they supplied to us, we always output the apartment line.0979

Now, we are going to optionally only do that if the user provides that; and that makes the application a little more real-world-oriented.0983

Let's take a look at the emailOrder function.0992

The emailOrder function is a utility function, so we create it in utilLIB.php.0996

And here is what it looks like: it takes four required arguments.1001

The first required argument is an associative array of all of the items in the user's Shopping Cart that a user is going to purchase.1006

It contains the order total, or the total that gets calculated by the calcCartTotal function, including sales tax.1013

It accepts a custData parameter, which provides all of the shipping information that a customer provided on the checkout.php form.1020

And then, it also includes the item catalog, which is going to allow us to look up item information1030

so that, when we create our email to the store administrator, we can include things such as an item's ID and an item's price and so forth.1034

The first thing we do when we enter the function is: we use the date function and use the ORDER_DATE_FORMAT constant1042

that we had previously created to generate a timestamp for the order when it was completed.1049

Then, what we do is: we start building up an email message to send to the store administrator, saying "an order was created on this order date."1054

And then, what it does is loops over all of the items in the cart; and this cartItems array is the same one that we have been using in checkout.php.1062

Its keys are the item ID's of any items in the shopping cart, and the values are the quantities of those items that the user wishes to purchase.1072

So, we loop over the items array, extracting the ID as the key and the quantity desired as the value,1080

and then, for each item that was purchased where the quantity is equal to 0, we output a line in our email.1089

And the email is going to say, "Item ID so-and-so was purchased; it has this price, and the quantity purchased was itemQty,"1095

which was what was provided by the cartItems array.1102

You can see here, we have a test condition that we only execute this code if itemQty is greater than 0.1106

And then, down here, you can see how we look up the item price.1112

Because the cartItems array only contains the item ID and its quantity, we need to look up the price of the item to include in our email.1117

So, we use this item catalog, which was passed in, which was that itemCatalog array that was created in our catalog.php form.1124

And we look up the item by its ID and then its price, using the price key.1132

And by passing this item catalog in, it shows how we have decreased our global dependency in this function,1137

because we could also access itemCatalog using the global keyword or the GLOBALS superglobal array.1146

But by passing it in, we eliminate that global dependency and allow this function to be reused in more spots.1153

Then, we go ahead and just output the order total right here, and then in the email, we loop over the customer data that was provided,1159

which includes all of the address information for the user.1168

And what we do is: because the information in custData is provided, it has keys which are variable names1171

(like firstName, for example, which is in this lower camel case notation).1179

When we output an email, we want to say "The first name was," and have a formatted output.1184

And we want to have first name, with a space in between, as opposed to this sort of variable name.1190

So, what we do is: we have created a switch statement that loops over each part of the address passed in from custData.1194

And if the current variable that you are looking over in the array equals either firstName, lastName, street, apt, city, state, or zipCode,1201

what it does is goes ahead and sets this string called formatted to the formatted output that we are going to put in our email.1211

When it gets to the end of the if statement, if formatted has been set (which means that there was an item in that custData array1220

that matched one of the cases in our switch statement--for example, a state was provided/a city was provided),1229

and also if the current address value that is being iterated over in the custData array is not empty,1234

then we go ahead and just output a line in our email address that has the formatted string that represents that part of the address.1243

So, for example, for the state, it is going to output State, with S capitalized, as opposed to just this variable name state.1254

For zipCode, it is going to output ZIP Code as two words, as opposed to this lower camel case notation variable.1265

And then, it is going to output whatever value the user provided.1271

We have built up this email that is going to contain all of the information about the items in the order.1276

It is going to contain an order timestamp; and then, it is also going to contain the shipping information that a user provided on checkout.php.1281

Then, down here, we call the mail function, which we have used before.1289

We send it, in this case, to the admin email, the store administrator's email, which we get using the ADMIN_EMAIL_TO constant that we had previously defined.1294

We include the email message we built up as the message to be sent.1305

And then, for the subject and the From email address, we use these two new constants that we have created in config.php.1309

And if we look at config.php, we can see, we have just added this constant ORDER_EMAIL_FROM,1318

which sets...when the store administrator receives an email, we have to set a from address for that,1324

so in this case, we just set it to the same as the admin email address, test@educator.com.1330

And then, we also create a constant, ORDER_EMAIL_SUBJECT, which is the subject line that the store administrator is going to see1335

every time an order is processed, and it is just going to say "Educator Store: Order Received."1341

And as we know, the mail function returns true if it was successful and able to pass the email on to the outgoing mail server.1350

So, what we return for this function is: if the sending of the email was not able to be performed--it was unsuccessful--1359

we are going to return the value false; if it was successfully sent, we are going to return the timestamp that we created1368

all the way at the beginning of the function, which is the timestamp of the order.1375

So, this function is going to return two different values, and it is going to depend on the value of sent,1379

which is the return value of the mail function.1384

Here you can see: for our return expression, we use a ternary operator that says, "If sent is true" meaning the mail function1388

was successful, "we are going to return the timestamp of the order that was created; and if not, we are going to return the value false."1395

And we are going to be able to use that in checkout.php to appropriately output a message as to whether or not the order placement was successful.1401

If we go and look at the new checkout.php, we can see...well, first of all, let's look at the beginning of the file.1410

We can see that, when the action is completeOrder (which means that the user has submitted the shipping information),1429

now, instead of just outputting the user's shipping information, this is where we call the emailOrder function.1437

And we provide it the cartItems array, the calculated order total, the array of customer data, shipping information,1444

and then also a reference to the item catalog in catalog.php.1452

And as we just learned, emailOrder returns false if the email wasn't successfully sent, and it returns the timestamp of the order if it was.1457

Here we have a test that if order timestamp is not true (meaning it is false), then we are going to set our error flag1464

and output an error message saying, "There is an error in completing your order."1473

If order timestamp is not equal to false, which means it turns out that it is equal to the order timestamp,1477

then we just set the page title as "Thank you for your order."1483

And then, down in the output section, we can access this order date/time variable that has the value returned by the emailOrder function.1486

And one thing to note is that, when you go to checkout.php, and you provide the action completeOrder,1498

that form...if we look at the old version of checkout.php, all it receives is the order total that was calculated after the user had submitted their shipping information.1507

And it also receives the custData; what it doesn't receive is what was included in the shopping cart.1531

And so, because our emailOrder function needs to know what was included in the shopping cart to output in the email,1537

we are going to have to (it would be easier if we just look at the page), when we submit the order and hit Checkout...1543

we are calling the checkout.php page with the action checkout.1560

What that does is submits the cartItems to the checkout.php, calculates the total, and then outputs this form.1564

When we go ahead and submit this form, we invoke checkout.php with the action completeOrder.1573

And previously, what it did was just output the timestamp of the order, which we had generated within checkout.php,1593

output the total, and then output the user's address.1599

However, because now when checkout.php gets submitted with the action completeOrder (when the user1603

hits the completeOrder button here), the emailOrder function is also going to need1609

all of the cartItems data that was passed in to checkout.php when the cart was submitted.1614

So, what we have to do is make use of that form functionality, and what we are going to do is create hidden input elements.1620

within this shipping information form that is going to contain all of the information about the items that were in the cart.1628

So, when we submit checkout.php with the action completeOrder, all of that cart item information gets passed along,1638

so we can access it in emailOrder and look up what items were purchased.1644

So, if we go and look at checkout.php, and we look in the email output section for checkout,1649

we can see that we have a form we created, that we have been using before, where we output this form1658

where the user can input their shipping information (their name, street, apartment, and so forth).1664

And then, this is actually the old version; and what we have is...we made use of forwarding the order total on to the completeOrder section of checkout.php.1671

Well, in the new version, we are adding to that form; so we are outputting the form; we are outputting a hidden input tag1681

that contains the order total; and then, what we are also going to do is loop over the cartItems array and, for each item1690

that was in the cart that has a quantity greater than 0, we are going to create a hidden input element1698

that is named items, which is the name we had given to the shopping cart items when we submit the viewCart.php form.1704

So, we are going to create an items array for each item, and set the key to the array equal to the item ID.1716

So, for any item that is in the shopping cart, we create a hidden input element for it.1724

We set its name equal to the items array, with the key being the item ID; and then we set the value equal to the quantity that the user set.1729

What that is going to do is: when we submit this form (and this form gets submitted to checkout.php),1736

but it gets submitted with the action completeOrder), all of these cart items' information is going to get passed along.1745

So, when we begin checkout.php all the way at the beginning, and we are processing the section (where is it?)1750

when action is completeOrder, and we go to use the emailOrder function, we will have access to this cartItems information, as well,1760

because they were forwarded along by including it in the bottom of that shipping form.1767

One other thing that we also did, just to clean up the look of the application, is: in the final page that shows a Thank You message,1773

which looks like this, if the user doesn't supply an apartment...before, we would still output apartment number.1782

For example, if we provided nothing, it would still be validated, because we said it was OK if the user doesn't provide an apartment.1793

And actually, this is the new version, so it works.1800

But in the previous version, it would output Apartment Number with a blank value.1802

What we have done here is updated checkout.php to include an if statement, so it checks if the custData array had the apartment value supplied.1808

And if it did, it goes ahead and outputs that line; and if it doesn't, then it just leaves it blank.1819

And so, to finish looking at this emailOrder function, let's look at the email that gets sent out when a customer submits an order.1825

And if we load up...I have an email loaded up in Thunderbird; we can see, the email says, "An order from the Educator Store was made."1835

It shows the timestamp that was created in the emailOrder function.1843

It shows a list of all the items that were in the shopping cart; when we looped over the cartItems quantity, we created a line for each item in there.1847

In this case, it had the item-1001, 1002...each with the quantity 1; and it lists their price.1856

Additionally, it lists the total that was calculated, including the sales tax.1861

And then, it also outputs the user's shipping and billing information.1867

From this, theoretically, the store administrator could go and, when they receive a manual payment for the order,1871

they could go ahead and process the order and ship it out.1876

And so, that is how that emailOrder function works to enable an order to be emailed to the site administrator when an order is completed.1879

In our last update to our web application, it is just going to be a formatting update.1892

One of the things that you might have noticed in previous versions of the web application...1898

for example, this was when we had checked out, just a moment ago, on version 16.0...1902

you can see that some of the dollar amounts aren't formatted correctly.1907

A dollar amount always has two digits after the decimal point.1912

Well, what we are going to do in 16.1...and if you go ahead and look at the cart, you can see, for example, here too,1916

that $15, the price of the t-shirt--it doesn't have a decimal point and two zeroes afterwards.1923

So, it is not formatted and does not look as nice as the other ones do.1928

We are going to create a function called formatAsDollars that is going to take a numeric value (in this case, a price of an item)1932

and then output a properly-formatted dollar string.1938

So, the function, again, that we are creating is going to be called formatAsDollars.1943

It is going to be located in utilLIB.php; it is going to format a numeric value; it is going to round it off, if it is not already rounded, to two decimal places.1947

It is going to always output two digits after the decimal place.1956

And then, it is also going to include the dollar sign in the formatted string.1960

And we use this function, for example, in our emailOrder function, when we send the email to our site administrator.1965

because that includes the total of the order; and then also, we are going to use it on all the pages where we display dollar amounts:1972

for example, the one we just looked at--the Shopping Cart--where we display the price of the items.1977

So, if we go ahead and look at the cart for 16.1, we can see that now the prices are properly output.1984

So, for example, if we add quantity 1 for a t-shirt, we can see: before, where it just output 16.5, it outputs the formatted dollar amount.1993

If we go and look at utilLIB.php in version 16.1, we have this formatAsDollars function.2007

It takes an amount; it uses the is_numeric function to test if an amount is a numeric value--2012

if it is an integer or a float or a string that represents an integer or a float.2019

If it is not, the default action of the function is: it is going to return a string that says "non-numeric."2024

That is maybe not the best way to handle errors, but with the skills that we have right now, that is one way of handling things.2032

We could test for that back in, for example, viewCart.php.2037

We could test to see that, when we try to format this dollar amount, if it returns non-numeric...to maybe not output anything,2045

or maybe just to output $15 without the properly-formatted two zeroes at the end.2051

So, that is the first thing that it does: it tests if it is a valid number, and it goes ahead and rounds it to two decimal places.2059

And then, here we just make use of some of the string functions that we had learned about in previous parts of the course.2065

We use the explode function to dissect the amount passed in, based on the decimal point.2071

If there are two parts (meaning there is a part before the decimal point and a part after), then we separate them into a pre part and a post part.2078

And then, we perform some tests on the number of digits in that post decimal part.2085

For example, if there are no digits, as is the case with the cotton t-shirt in our last version (there is no decimal point,2089

and there are no digits afterwards), then what we are going to do in the function2098

is go ahead and output two zeroes after the decimal point.2101

For example, if there is only one digit after the decimal point, we are going to append a zero to it, as well.2104

And then, we just return the pre-decimal part with this updated post-decimal part, appended with a dollar sign.2109

And then, when we return that to whatever script calls that, that formatted dollar amount is there.2118

So, as you can see, if we take a look at item.php (let's look at the current version--if we look at 16.1 item.php),2123

when we output the price, you can see that we changed it so that it uses that formatAsDollars function.2140

We have used that in a number of different places in the script: viewCart.php, also on the department.php page...2146

And then, we have used it within our function libraries in utilLIB.php, for example, in version 16.0,2152

where we have the email order function that we created in the last version.2158

We can see that, when we output the total in that email from the orderEmail function, we use the formatAsDollars function.2168

That just cleans up our application a little bit--makes it look more well-polished and more like a real, live web application.2176

And that is the last update that we are going to be doing to the web application.2184

For the last homework challenge we are going to have in this course, I just want you to go over and make sure you understand2188

how we use the is_array and is_string functions in various places, throughout the updates to the web application,2193

as a means of validating function inputs, because that is something...when you develop real-world code, you are going to want2199

to be doing your own, and be always testing your function inputs to make sure that they are valid values, or they are valid data types.2204

Also, examine how outputHtmlTag, the new function we created, improves the web application2211

by removing the redundant code where we had an outputImg and outputLink functions.2216

It moves it into one spot and creates a function that we can now use to create any HTML tag we desire, dynamically.2221

And we can use this in the future to create any other tag that we wish.2227

Additionally, just review how we have implemented that forwarding action.2232

When a user submits checkout.php with the action checkout (which is when they submit their shipping and billing information),2236

how all of that information is included in hidden input fields in that form, so that, when the completeOrder section of checkout.php2245

is executed, it will have access to the cart items that were provided and can generate the order email2258

that lists all of the items that were purchased.2268

Additionally, just make sure you understand how the formatAsDollars function works,2271

and how we have to use that function in order to output numeric data as decimal strings,2276

because numbers, when you convert them to strings in PHP, if they are floats (for example),2283

and it's just 16.50, it is not going to output 16.50--we have to use a string formatting function.2289

And the reason for that is just that the automatic conversion of floats to strings doesn't add that extra 0 in there to make it two decimal places.2296

And so, just understand how the formatAsDollars function provides us that opportunity to format that numeric string.2304

Thank you for watching today's lesson; I look forward to seeing you next time.2312

Educator®

Please sign in for full access to this lesson.

Sign-InORCreate Account

Enter your Sign-on user name and password.

Forgot password?

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Sign up for Educator.com

Membership Overview

  • Unlimited access to our entire library of courses.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lesson files for programming and software training practice.
  • Track your course viewing progress.
  • Download lecture slides for taking notes.

Use this form or mail us to .

For support articles click here.