Matthew M.

Matthew M.

Web Application Development

Slide Duration:

Table of Contents

Section 1: Advanced PHP with MySQL
Course Introduction

13m 36s

Intro
0:00
Advanced PHP w/ MySQL
0:13
Course Introduction
0:14
Course Content
0:59
Web Application: Educator Store
1:45
Web Application: Educator Store
1:46
Object-Oriented Programming
6:09
Object-Oriented Programming Overview
6:10
MySQL
6:50
MySQL Overview
6:51
Example: Command Prompt & MySQL
8:34
What You Will Learn
9:34
What You Will Learn
9:35
Course Prerequisites
11:52
Course Prerequisites
11:53
Advanced Course Development Environment

18m 46s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Development Environment Setup
1:36
Firefox Web Browser, XAMPP, and PSPad Text Editor
1:37
Course Directory Structure
4:36
Course Directory Structure
4:37
phpDocumentor
7:23
phpDocumentor Overview
7:24
Parsing Source Code
7:44
docs Subdirectory
9:06
Asvanced PHP Course Documentation Example
10:21
Previous Educator PHP Students
14:14
Lib Directory Changes
14:38
Images Directory Changes
14:57
VERSION Constant
15:40
Comments Noting a Specific Version Number
17:04
Homework Challenge
17:30
Homework Challenge
17:31
Introduction to File I/O

35m 37s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
File I/O
1:34
File I/O Overview
1:35
Performing file I/O: 3 Steps
1:52
File Permissions
2:28
Read Permission & Write Permission
2:29
fopen()
4:47
fopen()
4:48
Two Required Parameters
5:01
Successful fopen(): File Handle and Resource
5:21
FALSE and E_WARNING Error
6:00
Example
6:39
File Paths
7:10
File Paths
7:11
File Access Modes
9:18
File Access Modes
9:19
Coding Example: fopen()
10:31
Using Relative and Absolute Path & Non-Existent File
10:32
File Pointers
15:55
File Pointers
15:56
Example File
16:11
Opening a File with fopen() Using 'r' as the Access Mode
16:22
fgets()
17:55
fgets() Overview
17:56
Coding Example: fgets() - Reading a Line at a Time
18:26
feof()
20:10
feof() Overview
20:09
Coding Example: feof()
20:50
fclose()
23:43
fclose() Overview
23:44
Coding Example: fclose()
25:02
Coding Example: Current Stock
26:10
Coding Example: Current Stock
26:11
trim ()
31:39
trim () Overview and Example
31:40
Homework Challenge
33:35
Homework Challenge
33:36
Web Application Development

36m 36s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Version 1.0 Changelog
0:31
catalog.php
0:32
Function Library: fileLIB.php
5:00
Version 1.1 Changelog
27:12
createItemDataArray() and createDeptDataArray()
27:13
outputSimpleItemLink() and outputSimpleDeptLink()
32:06
HTTP & the POST Method

34m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
HTTP Model
1:28
HTTP Model
1:29
Client-Server Model 2 Steps Process
2:00
HTTP Messages
2:23
HTTP Messages
2:24
HTTP Requests
3:09
HTTP Requests
3:10
Example: HTTP Request Header
3:17
Coding Example: HTTP Requests
4:29
HTTP Responses
7:15
HTTP Responses
7:16
Example: HTTP Response (Header & Body)
8:00
header()
11:47
header() Overview
11:48
Coding Example: header
14:02
Coding Example: header() Error
14:52
GET Method
18:55
GET Method
18:56
Coding Example: GET Method
20:13
POST Method
21:09
POST Method
21:10
Coding Example: Sample Form Using the POST Method
23:50
Accessing POST Data in PHP
26:38
Accessing POST Data in PHP
26:39
Coding Example: Accessing POST Data via $_POST
28:15
GET vs. POST
29:54
GET vs. POST
29:55
Example: Accessing POST Data via $_POST
31:20
Example: Accessing POST Data via $_POST
31:21
Homework Challenge
33:00
Homework Challenge
33:01
Web Application Development

14m 11s

Intro
0:00
Version 2.0 Changelog
0:09
Updating the Site's Current Form to Use the POST Method
0:10
Creating Admin Website
2:55
Dynamically Generated Department List
12:40
Writing to Files

17m 38s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Review of File I/O
0:40
Review of File I/O
0:41
fwrite()
1:38
fwrite()
1:39
fputs()
2:20
'r+'
2:31
Coding Example: fwrite()
2:59
fopen() Access Modes
8:41
'a' and 'a+'
8:42
'w' and 'w+'
11:34
Homework Challenge
14:47
Homework Challenge
14:48
Web Application Development

28m 14s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Updated Open File Functions
0:19
openItemsDataFile ( ), openDeptsDataFile ( ), and openLastAddedFile ( )
0:20
insertItem()
6:25
insertItem() Overview
6:26
Functions: createItemDataString ( ) and updateLastItemAdded ( )
7:07
addItemToDepartment ()
16:03
addItemToDepartment () Overview
16:04
Functions: createDeptDataString ( ) and updateDepartment ( )
17:55
HTTP POST: File Uploads

22m 51s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
POST Data Encoding
1:13
POST Data Encoding
1:14
When Data is Included in the Body of the HTTP POST Request and is of the Content Type
1:31
When Uploading Files Using HTTP POST
3:17
Uploading Files
6:22
Uploading Files
6:23
If Encoding Type is Not Set to Multipart/Formdata
9:27
$_FILES Superglobal
10:59
$_FILES Superglobal
11:00
Structure of $_FILES
12:15
Structure of $_FILES: Name, Type, tmp_name, Error, and Size
12:16
Coding Example: $_FILES Superglobal
13:34
Moving an Uploaded File
15:39
Introduction to Moving an Uploaded File
15:40
move_uploaded_file ( ): Definition and Example
16:40
Homework Challenge
21:19
Homework Challenge
21:20
Web Application Development

15m 30s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Uploading Item Image File
1:22
Uploading Item Image File
1:23
Uploading Item Image File (cont.)
2:43
Altering insertItem ( )
2:44
Helpfer Functions: getFileExtension ( ) and moveUploadedFile ( )
4:30
isValidItem ( )
13:03
Introduction to Object-Oriented Programming

32m 44s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object-Oriented Programming
0:56
Introduction to Object-Oriented Programming
0:57
Associative Arrays
5:27
Associative Arrays
5:28
Classes
7:27
Classes Overview
7:28
Defining Classes
8:24
Defining Classes
8:25
Declaring Class Properties
9:25
Coding Example: Classes
10:11
Objects
12:18
Objects Overview
12:19
Classes vs. Objects
12:49
Classes vs. Objects
12:50
Instantiating Classes
14:58
Instantiating Classes
14:59
Coding Example: Instantiate an Item Object
16:30
Object Properties
19:21
Access and Set an Object's Property
19:22
Coding Example: Set & Access the Properties of an Item Object
24:23
Homework Challenge
30:22
Homework Challenge
30:23
Web Application Development

17m 47s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 5.0 Overview
0:50
Version 5.0 Overview and Examples
0:51
Outputting Object Properties
12:38
Outputting Object Properties
12:39
Array Object Properties
14:18
Access and Set Array Value
14:19
Object Methods

39m 57s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Object Methods
0:52
Definition of Object Methods
0:53
Calling Object Methods
3:25
Calling Object Methods
3:26
Coding Example: Simple Object Methods
4:44
Object Methods and Return Values
7:02
$this Variable
10:06
$this Variable: Definition and Example
10:07
$this Variable (cont.)
15:51
$this Variable (cont.)
15:52
Getters & Setters
21:21
Getters & Setters Methods
21:22
Object Methods In Strings
25:46
Object Methods In Strings
25:47
Coding Example: Outputting Method Return Values in Strings
27:41
Using $this to Call Other Methods
28:49
Using $this to Call Other Methods
28:50
Homework Challenge
34:18
Homework Challenge: 1-3
34:19
Homework Challenge (cont.)
36:20
Homework Challenge: 4-6
36:21
Homework Challenge (cont.)
37:52
Homework Challenge: 7-10
37:53
Web Application Development

17m 30s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 6.0 Overview
0:40
Version 6.0 Changes & Examples
0:41
Item Methods
0:53
Item Class Definition: getImageFilename()
0:54
Coding Example: getImageFilename()
1:58
Department Methods
7:33
addItem(), removeItem(), and isItemInDept() Method
7:34
addItemtToDepartment() & buildDeptObject() Functions
11:46
A Default Value Needed to Be Set for $items
16:26
Object Constructors

22m 20s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object Constructors
0:32
Introduction to Object Constructors
0:33
Coding Example: Object Constructors
1:43
Defining Constructors
3:26
Defining Constructors
3:27
Coding Example: Constructors with No Arguments
4:24
Constructor Arguments
8:09
Constructor Arguments
8:10
Coding Example: Constructor Arguments
9:49
Important Notes
16:13
Important Notes
16:14
Homework Challenge
17:35
Homework Challenge: 1 - 4
17:36
Homework Challenge (cont.)
19:13
Homework Challenge: 5 - 9
19:14
Homework Challenge (cont.)
21:40
Homework Challenge: 10 and 11
21:41
Web Application Development

16m 19s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 7.0 Overview
0:39
Version 7.0 Overview
0:40
Item Constructor
2:19
Item Constructor
2:20
Department Constructor
7:47
Department Constructor
7:48
Customer Constructor
12:23
Customer Constructor
12:24
More Magic Methods

53m 37s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Magic Methods
1:12
Magic Methods
1:13
Destructors
2:45
Destructors Overview
2:46
Coding Example: Calling Destructors
4:30
Coding Example: Object Destructor
9:19
_to String ()
16:12
_to String () Overview
16:13
Coding Example: _to String () Magic Method
18:10
Access Modifiers
21:23
Introduction to Access Modifiers
21:24
Access Modifiers: Public
21:39
Access Modifiers: Private
22:18
Access Modifiers: Protected
22:41
Object Properties and Methods
23:06
Coding Example: Public Access Modifiers
26:48
Coding Example: Private Access Modifiers
28:30
_get()
31:37
_get() Overview
31:38
Coding Example: _get () Magic Method
33:30
_set ()
36:23
_set () & the Magic Method
36:24
Using Getters & Setters
44:37
Coding Example: Using Getters & Setters
44:38
Homework Challenge
50:33
Homework Challenge: 1 - 6
50:34
Homework Challenge (cont.)
51:41
Homework Challenge: 7 - 12
51:42
Web Application Development

31m 12s

Intro
0:00
Version 8.0 Review
0:12
Version 8.0 Review
0:13
private Object Properties
1:15
private Object Properties
1:16
Coding Example
2:54
_toString() Methods
6:51
_toString() Methods
6:52
Coding Example
8:09
DataFile Class
13:27
DataFile Class & I/O Operations
13:28
Using DataFile Class: Instantiate a DataFile, DataFile open () Method, and DataFile close () Method
18:09
Homework Challenge
29:35
Homework Challenge
29:36
Classes vs. Objects

37m 49s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Class vs. Object Review
0:58
Class vs. Object Review
0:59
Static Properties
2:42
Static Properties
2:43
Scope Resolution Operator (::)
5:26
Scope Resolution Operator (::) & Static Property
5:27
Coding Example: Accessing a Static Property Using the Scope Resolution Operator
7:57
Coding Example: Accessing a Static Property in a Class Definition
10:33
Coding Example: Using a Static Property as an Instance Counter
14:18
Static Methods
18:51
Static Methods Overview
18:52
Coding Example: Static Methods
21:39
Classes vs. Objects
26:28
Classes vs. Objects: Diagrams
26:29
Class Constants
30:24
Class Constants Definition
30:25
Coding Example: Using Class Constants
31:55
Homework Challenge
34:01
Homework Challenge: 1 - 5
34:02
Homework Challenge (cont.)
35:25
Homework Challenge: 6 - 10
35:26
Web Application Development

21m 7s

Intro
0:00
Version 9.0 Overview
0:12
Version 9.0 Changes & Examples
0:13
Output Class
1:08
Output Class & Static Methods
1:09
outputHtmlSelector ( ) Method
2:43
outputItemSelector ( ) Method
4:53
outputDeptSelector ( ) Method
6:42
buildObject() Methods
11:54
buildObject() Methods & Examples
11:55
Exceptions

22m 43s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
try Blocks
0:44
try Blocks Definition
0:45
catch Blocks
2:03
catch Blocks: Definition and Syntax
2:04
Coding Example: try/catch Blocks
3:48
When an Exception Object is Caught & Error Handling
5:59
Exception Class
7:02
Exception Class
7:03
Coding Example: Using try/catch to Catch an Exception Thrown from a Method
8:04
Re-Throwing Exceptions
16:39
Re-Throwing Exceptions
16:40
Coding Example: Re-throwing an Exception
17:21
Homework Challenge
20:40
Homework Challenge: 1 - 5
20:41
Homework Challenge (cont.)
22:17
Homework Challenge: 6
22:18
Web Application Development

22m

Intro
0:00
Version 10.0 Overview
0:11
Updating addItem.php, addItemToDept.php, and error.php
0:12
Updating DataFile Class: open ( ) Method & try/catch blocks
7:45
Version 10.1 Overview
13:37
Version 10.1 Changes & Examples
13:38
Updating DataFile Class: close ( ) Method & logWarning ( )
20:17
Cookies

39m 47s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is a Cookie?
1:15
Definition of Cookie
1:16
HTTP - A Stateless Protocol
2:17
HTTP - A Stateless Protocol
2:18
Purpose of Cookies
4:10
Set - Cookie Header
6:21
Introduction to Set - Cookie Header
6:22
Coding Example: Set - Cookie Header
7:38
Cookie Header
9:45
Introduction to Cookie Header
9:46
Example: Cookie Header
10:27
setcookie()
12:33
Introduction to setcookie()
12:34
Example: Using setcookie
13:54
Cookies Attributes
15:48
Cookies Attributes Overview
15:49
Common Cookies Attributes: Domain
16:24
Common Cookies Attributes: Path
17:04
Common Cookies Attributes: Expires
19:34
Coding Example: Setting Cookie Attributes
20:58
$_COOKIE Superglobal
27:03
$_COOKIE Superglobal
27:04
Coding Example: Accessing Cookies from PHP Using $_COOKIE
29:45
Security Implications
34:44
Security Implications
34:45
Homework Challenge
36:10
Homework Challenge: 1 - 4
36:11
Homework Challenge (cont.)
37:47
Homework Challenge: 5 - 7
37:48
Web Application Development

39m 11s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
instanceof Operator
1:34
instanceof Operator
1:35
Objects with Object Properties
2:53
Objects with Object Properties
2:54
Version 11.0 Overview
6:41
Version 11.0 Changes: Cart and CartItem Classes
6:42
Version 11.0 Coding Example
10:40
Version 11.1 Overview
31:03
Version 11.1 Changes & Examples
31:04
Introduction to Sessions

46m 8s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
What is a Session?
0:53
What is a Session?
0:54
Client-Side Sessions
3:51
Client-Side Sessions
3:52
Server-Side Sessions
5:04
Server-Side Sessions
5:05
Session IDs
6:26
Session IDs
6:27
The SID is Used by the Server to:
7:08
A Client Passes an SID to the Server with Each HTTP Request Via:
8:15
Sessions in PHP
12:19
Sessions in PHP
12:20
session_start()
14:40
session_start() Overview
14:41
Coding Example: Using session_start () to Continue a Session
18:03
$_SESSION Superglobal
22:06
$_SESSION Superglobal Overview
22:07
Coding Example: Setting a Session Variable via $_SESSION
25:22
Accessing Session Data
28:08
Accessing Session Data
28:09
Deleting Session Data
31:43
Deleting Session Data
31:44
Coding Example: Deleting Session Data
32:16
Configuring PHP Sessions
36:14
session.cookie_lifetime, session.cookie_domain, and session.cookie_path
36:15
Coding Example: Configuring PHP Sessions
37:28
Configuring PHP Sessions (cont.)
40:56
session.use_cookies, session.use_trans_sid, and session.use_only_cookies
40:57
Coding Example: Configuring PHP Sessions
42:25
Homework Challenge
42:55
Homework Challenge: 1 - 5
42:56
Homework Challenge (cont.)
44:10
Homework Challenge: 6 - 10
44:11
Homework Challenge (cont.)
45:27
Homework Challenge: 11 - 13
45:28
Web Application Development

11m

Intro
0:00
Version 12.0 Overview
0:12
Version 12.0 Changes Part I: Updating 'viewCart.php' & 'checkout.php'
0:13
Version 12.0 Changes Part II
5:03
Destroying Sessions

29m 59s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Destroying Sessions
1:02
Destroying Sessions
1:03
session_destroy()
2:10
session_destroy() Overview
2:11
Coding Example: Setting a Session Variable and Destroying a Session
3:18
Deleting Session Cookies
8:38
Deleting Session Cookies
8:39
Coding example: Deleting Session Cookies
9:17
Review of Steps
21:07
Review of Steps
21:08
Garbage Collection
21:50
Garbage Collection Overview
21:51
Coding Example: Garbage Collection
24:30
Homework Challenge
26:28
Homework Challenge: 1 - 4
26:29
Homework Challenge (cont.)
28:16
Homework Challenge: 5 - 9
28:17
Web Application Development

19m 14s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
_autoload()
0:46
Introduction to _autoload ()
0:47
Version 13.0 Overview
4:06
_autoload () and SessionManager Class
4:07
Updating 'viewCart.php' & 'checkout.php'
11:16
Introduction to Databases

21m 24s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Flat Files
1:09
Flat Files: Definition and Example
1:10
Problems Associated with Using Flat Files as a Database
2:15
Relational Databases
3:29
Relational Databases
3:30
Relational Database Management System (RDBMS)
3:50
Tables
7:43
Tables
7:44
Columns
9:24
Columns
9:25
What is SQL?
10:45
Introduction to Structured Query Language
10:46
Standard Data Types of SQL
12:23
Primary Keys
13:19
Primary Keys
13:20
Primary Key Examples
16:36
Primary Key Examples
16:37
Introduction to MySQL

28m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
What is MySQL?
1:33
MySQL
1:34
MySQL Monitor
5:16
MySQL Monitor Overview
5:17
XAMPP & MySQL
5:58
In the MySQL Command: hostname, username and -p
7:05
Connecting to a MySQl Server
9:52
Connecting to a MySQl Server
9:53
Using MySQl Monitor
13:48
Using MySQl Monitor
13:49
GRANT Command
15:10
GRANT SQL Command
15:11
Privileges & Objects
18:18
Username, Hostname, and Password
19:37
Specifying Objects
20:05
Creating a PHP User Account
21:41
Creating a PHP User Account Overview
21:42
Meaning of all & *.*
23:35
Example: Creating a PHP User Account
23:48
Required Homework
26:27
Required Homework: 1 - 5
26:28
Required Homework (cont.)
27:28
Required Homework: 6
27:29
Creating Databases & Tables

23m 1s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Creating a Database
1:40
Introduction to Creating a Database
1:41
Example: Creating a Database
3:33
CREATE TABLE Command
6:43
CREATE TABLE Command
6:44
Data Types
7:39
Numeric Data Types: INT, INT UNSIGNED, and DECIMAL
7:40
String Data Types: CHAR (M), VARCHAR (M), and TEXT
9:23
Colum Attributes
11:00
PRIMARY KEY Attribute
11:01
AUTO INCREMENT Attribute
11:35
Items Table
13:07
Items Table
13:08
Useful Commands
17:04
SHOW TABLES Command & DESCRIBE Utility Statement
17:05
Example: Creating an Items Table
17:58
Required Homework
20:51
Required Homework: 1 - 6
20:52
Required Homework (cont.)
21:55
Required Homework: 7 - 9
21:56
SQL Command: INSERT

27m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
INSERT Command
1:20
SQL INSERT Command
1:21
Specifying Values
3:16
Columns with Numeric Data Types
3:17
Columns with String Data Types
3:34
Columns with AUTO INCREMENT
4:07
Inserting Items
5:21
Inserting Items
5:22
Example: Inserting Items
7:03
SQL Text Files
14:04
SQL Monitor Client
14:05
MySQL Monitor & the < Operator
15:15
Example
17:35
Required Homework
22:32
Required Homework: 1 - 6
22:33
Required Homework (cont.)
24:19
Required Homework: 7 - 10
24:20
SQL Command: SELECT

24m 57s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
SELECT Command
0:42
SELECT Command: Definition and Syntax
0:43
Results of a SELECT Query
1:53
To Specify the Retrieval of All Columns from a Table
3:06
Example: SELECT Command
4:18
WHERE Clause
7:11
WHERE Clause
7:12
A SELECT Query with WHERE Clause has the Following Syntax
8:10
A Where Condition can Contain both Logical and Comparison Operators
9:44
Literal Values
13:24
Literal Values
13:25
Example: Literal Values
14:18
ORDER BY Clause
15:31
ORDER BY Clause & SELECT Query
15:32
Ascending and Descending Order
17:30
An ORDER BY Clause can Specify Multiple Columns to Order the Rows by
18:01
Example: SELECT Query with WHERE and ORDER BY Clause
20:32
Homework Challenge
21:59
Homework Challenge
22:00
Homework Challenge (cont.)
23:54
Homework Challenge
23:55
Using PHP from MySQL

32m 43s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
PHP/MySQL Architecture
0:56
PHP/MySQL Architecture
0:57
MySQLi Extension
3:05
MySQLi Extension
3:06
Steps to Using MySQL from PHP
5:53
Four Steps to Using MySQL from PHP
5:54
Step # 3
7:18
Connecting to a Database
8:12
To Connect to a MySQL Database
8:13
To Test for Connection Errors
10:20
Running an SQL Statement
11:54
Running an SQL Statement
11:55
Example
13:30
Processing the Results
15:58
For non-SELECT Queries
15:59
MySQLi Object Property: affected_rows
16:19
For INSERT Statements on Tables with an AUTO_INCREMENT Column
18:07
Closing the Connection
19:45
Closing the Connection
19:46
Coding Example
21:24
Coding Example: Using MySQL from PHP
21:25
Homework Challenge
29:00
Homework Challenge: 1 - 4
29:01
Homework Challenge (cont.)
31:10
Homework Challenge: 5 - 9
31:11
Web Application Development

30m 30s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
sprintf()
1:28
sprintf() Overview
1:29
Example
1:56
INSERT Statements with sprintf()
5:15
INSERT Statements with sprintf()
5:16
Version 14.0 Overview
10:00
Version 14.0 Changes & Examples Part 1
10:01
Version 14.0 Changes & Examples Part 2
21:58
SELECT QUERIES from PHP

24m 22s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
SELECT Queries
1:21
SELECT Queries
1:22
MySQLi_Result Class
3:17
MySQLi_Result Class: num_rows
3:18
MySQLi_Result Class: fetch_assoc ( ) and fetch_object ( )
3:59
fetch_assoc()
5:17
fetch_assoc() Overview
5:18
Coding Example: Using fetch_assoc()
9:00
stdClass Objects
12:46
stdClass Objects
12:47
fetch_object()
14:19
fetch_object() Overview
14:20
Coding Example: Using fetch_object()
16:45
Freeing Result Set Memory
18:42
Freeing Result Set Memory
18:43
Coding Example: Using free ( )
20:01
Homework Challenge
22:07
Homework Challenge: 1 - 5
22:08
Web Application Development

17m 6s

Intro
0:00
Version 15.0 Overview
0:13
Version 15.0 Changes & Examples Part 1
0:14
Version 15.0 Changes & Examples Part 2
8:43
Linking Tables

24m 32s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
A Departments Table
1:08
Departments Table
1:09
How Could We Model This in a Table: Option 1
1:26
How Could We Model This in a Table: Option 2
3:12
Database Normalization
4:37
Database Normalization
4:38
Foreign Keys
8:47
Foreign Keys
8:48
Linking Table
11:26
Linking Table
11:27
Multiple Column Primary Keys
15:30
Multiple Column Primary Keys
15:31
Example
18:51
Required Homework
22:34
Required Homework: 1 - 3
22:35
Required Homework (cont.)
24:10
Required Homework: 4
24:11
Web Application Development

24m

Intro
0:00
Version 16.0 Overview
0:11
Version 16.0 Changes
0:12
Version 16.0 Coding Examples
4:12
Version 16.0 (cont.)
18:30
Version 16.0 Changes & Examples Part 2
18:31
SQL Command: DELETE

10m 33s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
DELETE Statement
0:30
DELETE Statement & Its WHERE Clause
0:31
Delete All Rows From a Table
2:57
Using DELETE from PHP
4:04
Using DELETE from PHP Overview
4:05
Coding Example: Using DELETE from PHP
6:37
Homework Challenge
8:53
Homework Challenge: 1 - 4
8:54
Web Application Development

16m 2s

Intro
0:00
Version 17.0 Overview
0:11
Version 17.0 Changes
0:12
Version 17.0 Coding Example
2:51
Transactions
12:50
Database Transaction
12:51
Steps in Using Transactions
14:00
SQL Command: UPDATE

32m 14s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
UPDATE Statement
0:54
UPDATE Statement & Its WHERE Clause
0:55
Example: UPDATE Statement
3:32
Using UPDATE from PHP
5:21
Using UPDATE from PHP Overview
5:22
Coding Example: Using UPDATE from PHP
6:53
htmlspecialchars()
9:04
htmlspecialchars()
9:05
Encoding Special Characters
9:23
Coding Example: htmlspecialchars()
13:41
addslashes()
20:40
addslashes()
20:41
Coding Example: addslashes()
22:52
Homework Challenge
27:55
Homework Challenge: 1 - 2
27:56
Homework Challenge (cont.)
30:14
Homework Challenge: 3 - 5
30:15
Homework Challenge (cont.)
30:41
Homework Challenge: 6 - 9
30:42
Web Application Development

12m 33s

Intro
0:00
Version 18.0 Overview
0:12
Version 18.0 Changes
0:13
Version 18.0 Coding Example
1:24
SQL: Joins

42m 16s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
DATETIME Data Type
1:52
DATETIME Data Type
1:53
Modeling Orders
5:12
Modeling Orders
5:13
Customers Table
10:46
Customers Table
10:47
Example
16:18
Example: Order Table in MySQL
16:19
Joins
22:26
Joins Overview
22:27
Inner Join
23:09
Example: Joins
24:11
Join Conditions
28:14
Join Conditions
28:15
Example
28:32
Join Queries
30:00
Example: Join Conditions in MySQL
30:36
Implicit Joins
34:42
Implicit Joins
34:43
Example: Implicit Joins
35:57
Aliases
37:28
Introduction to Aliases
37:29
Example: Aliases
38:55
Required Homework
40:32
Problem 1
40:33
Problem 2
41:01
Problem 3
41:17
Web Application Development

29m 34s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Inserting Orders
0:44
Inserting Orders
0:45
Version 19.0 Overview
3:45
Version 19.0 Changes & Example Part 1
3:46
Version 19.0 Changes & Example Part 2
13:18
Version 19.1 Overview
21:10
Version 19.1 Changes
21:11
Version 19.1 Coding Example
22:18
User Authentication

26m 13s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
User Authentication
1:31
User Authentication
1:32
Authentication with Sessions
2:34
Authentication with Sessions
2:35
Four Steps in Authentication via Sessions
2:50
Using Sessions to Restrict Access
3:58
Using Sessions to Restrict Access
3:59
Coding Example: Restricted Access Area
4:47
Authentication Methods
5:54
Authentication Methods Overview
5:55
Coding Example: Authentication Methods
7:31
Logging Out
9:57
Logging Out
9:58
Coding Example: Log Out
10:47
Users Table
13:50
Users Table
13:51
Example: Creating a Users Table
15:08
Password Hashing
17:30
Password Hashing
17:31
PHP and MySQL Built-in Hash Functions: sha1 ( ) and md5 ( )
18:43
Coding Example: Password Hashing
19:27
Required Homework
24:41
Required Homework: 1 - 4
24:42
Web Application Development

14m 36s

Intro
0:00
Version 20.0 Overview
0:13
Version 20.0 Changes & Examples Part 1
0:14
Version 20.0 Changes & Examples Part 2
5:05
Version 20.0 Changes & Examples Part 3
7:29
Version 20.0 (cont.)
8:31
Version 20.0 Changes & Examples Part 4
8:32
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 Advanced PHP
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
Since this lesson is not free, only the preview will appear on your website.
  • 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:17
    • Lesson Overview
  • instanceof Operator 1:34
    • instanceof Operator
  • Objects with Object Properties 2:53
    • Objects with Object Properties
  • Version 11.0 Overview 6:41
    • Version 11.0 Changes: Cart and CartItem Classes
    • Version 11.0 Coding Example
  • Version 11.1 Overview 31:03
    • Version 11.1 Changes & Examples

Transcription: Web Application Development

Hello again, and welcome back to Educator.com's Advanced PHP with MySQL course.0002

In today's lesson, we are going to be continuing development of our web application.0007

We are going to be incorporating what we learned in our last lesson about cookies to improve the functionality of our site's shopping cart.0011

We are going to introduce a couple of small topics before we get into the actual changes we made to the web application.0019

We are going to be talking about a new operator called the instanceOf operator.0026

And then, we are also going to be talking about how to access properties of objects that are properties of other objects.0031

And we will see a little more about what that looks like on the slide coming up.0038

Then, we are going to go through two different versions of the web application.0042

In version 11.0, what we are going to be doing is creating a shopping cart object.0045

It is going to be called a Cart--that is the name of the class.0051

And we are going to use that to represent our shopping cart.0056

Right now, we have been using an associative array that we have been passing around,0059

called items, that has keys that are the item ID of the item in the shopping cart, and then its value is the quantity.0064

Well, we are going to change that and put it into an object.0074

In 11.1, what we are going to do is implement a shopping cart that uses cookies.0078

So, in 11.0, we are going to convert things over to an object model for our shopping cart; in 11.1, we are going to0084

use that object model with cookies to get a more functional shopping cart.0090

PHP provides what is called the instanceOf operator, and what it allows you to do is determine whether a variable is an instance of a specific class type.0096

For example, if we have a variable called object, or obj, and we want to test0107

to see if it is, for example, an instance of the Item class that we use in our web application;0113

The way you would do that is: instanceOf is a binary operator; you put the variable that you are testing the type of on the left-hand side.0119

And then, you put the exact name of the class on the right-hand side of the operator, and this becomes a boolean expression.0127

So, what it does is says, "If object is an instance of the Item class, return true; if it's not, return false."0134

isItem would be true if object is an Item, and it would be false if it isn't.0142

This is useful for when you are accepting parameters from functions and so forth,0146

to test and make sure that you are getting appropriate objects that you might be working on.0151

For example, if you need an Item object to work on, you need to be sure that you are passed an Item object, as opposed to an Integer, for example.0156

And again, you need to make sure that you use the exact name of the class to the right of the operator.0164

And it is just the name of the class; there is no dollar sign or anything like that.0169

Also, we know that an object has properties.0175

And the data types of an object's properties can be any data type, which includes other objects.0178

So, for example, we could have a Cart class, and we could define a variable item that is intended to be a variable that represents an Item object.0185

What we have is an object within an object; so how do we access the properties of the Item object that is a part of the Cart object?0206

Well, we use the arrow operator and a cascaded syntax.0214

Let's say, for example, we have a Cart class, like the one above, that has a property named Item, as it does up here,0219

which is an Item object; that is the data type of that property.0226

And let's assume that the Item object is the Item that we use in our web application.0231

So, the Item object, we know, has a price property. How do we access the price property?0235

Let's say we have an instance of the Cart class; we have created an instance of Cart called cart.0242

Let's not worry about the details behind it.0248

But it has been set up; an item has been added to it, so the item has been set to a new Item object, for example--maybe in the constructor of the cart.0249

And we want to access the price of this particular Item object.0260

Well, the way you do that is using multiple arrow operators.0264

For example, we get the instance of our Cart object, and then we use the arrow operator to say, "Give me the item property."0268

And what that is going to do is return the instance of the Item object that this current instance of the Cart item property is set to.0277

And then, now that this is an object, we can again call the arrow operator on it to say, "Now I want the price property of this object."0288

In this case, this is an Item object that was taken from the Cart object; and so, this is saying how to get the price from it.0297

And you can do this indefinitely; you can have objects within objects within objects.0304

And the reason I am introducing in now, as well as the instanceOf operator, is because these are some things0309

that are getting introduced into the versions of the web application we are going over in today's lesson.0314

So, let's say Price was even an object, and maybe it had a property that was called currency, that lets you know the currency it was in.0320

And we could access it like so, and that goes on down the line.0330

This also works with class properties that are arrays of objects.0336

For example, let's say, in our cart, instead of just having an Item object, we had an associative array of Item objects,0341

where the key to that array is an item ID, and then the values are Item objects.0348

What you can do is say, "For this Cart instance, give me the Item object that is in the items associative array, associated with the key item-1001."0357

This is going to return an Item object, and then because it is an object, we can use the arrow operator on it to get the price of it.0369

And so, this is going to say, "Give me the price of this Item object."0378

This is saying, "Get me the price of item-1001 that is in this particular Cart instance."0382

This would be assuming that it has an item 1001, and so forth.0390

But that just demonstrates how you can also access object properties that are arrays of objects.0393

Now, we are going to get into the nuts and bolts of the changes we are making in this web application.0403

We are introducing two new objects into our web application: Cart, and one called CartItem.0408

And what they are is classes that are created to model a shopping cart.0415

That is what we do with object-oriented programming; we model real-world objects.0419

We have a Cart class, and as in the last slide's example, it is going to contain a property called cartItems.0425

And this cartItems is going to be an associative array of CartItem objects.0445

So, we have another object that we are creating called CartItem.0452

And what this does is represents an item that is in a cart.0457

We set it up so that it has two properties: one is called item, and one is called quantity.0464

For example, in our shopping cart, when we add an item to a shopping cart, we add the item, and then we also have a quantity associated with it.0471

We are going to encapsulate that into one object.0478

It is a CartItem object; it is going to contain an Item object, which is the store item that this CartItem represents.0481

And then, it is also going to have an Integer property, quantity, that is going to represent what quantity of that item is currently in the shopping cart.0488

Now, in our shopping cart, this is an associative array; it is going to have keys that are item ID's for items in the shopping cart.0496

And what they are going to point to is CartItem objects, which, as mentioned over here, contain an Item and a quantity.0504

We have this Cart object that contains an associative array of a number of CartItems.0519

And a CartItem is an object that encapsulates a store item, along with its associated quantity.0525

What we can do, then, is: we are also going to be creating a method for our CartItem class called calcItemTotal.0532

What that is going to allow us to do is: because this CartItem class knows what Item it represents, and it knows the quantity,0544

it has access to the price of the Item; it also has access to the quantity of the Item.0553

So, we can calculate the cost due to this particular Item in the Cart.0557

And that would be the price of the Item, times whatever quantity it is in.0562

So, what we can do in our Cart class is: we are going to create a method called calcTotal.0566

And what that is going to do is loop over, when we need to calculate the total of a shopping cart, all of the CartItem objects within its cartItems array.0573

And it is going to call the calcItemTotal on each of those items.0584

Instead of having to manually go and look up the item and get its price, and then multiply it times the quantity,0588

it is going to have the CartItem object do it for us by this calcItemTotal method.0595

This is going to loop over all of the different CartItem objects within the cart.0600

It is going to add up their totals, multiply it times the sales tax rate, and then generate the total for the entire cart.0604

So, each CartItem generates the total due to that item, and then the Cart takes all of those CartItem objects together,0614

adds them up, and then calculates sales tax.0622

So, we are going to be replacing our former method (that was just a user-defined function called calcCartTotal).0624

And that functionality is going to be moved into this Cart class, as well as this CartItem class.0633

Let's go and take a look at what these classes look like.0640

Look at version 11.0...well, first let's look at the CartItem.0645

Our CartItem class, if we look at the source code, has two properties: item and quantity.0655

quantity is an integer representing the amount of this particular item in the cart.0663

item is an Item object that represents the actual store item that this CartItem represents.0667

This object is an Item and its associated quantity.0674

We have a constructor that takes an Item object and an integer for the quantity, and just sets those private properties.0680

And then, here is our calcItemTotal method that we had talked about.0687

What that does is returns the total due to this particular item in a particular shopping cart.0692

For example, it multiplies the item price times its quantity.0698

Well, it gets the quantity from this CartItems variable quantity; so it says $this and then gets the quantity.0701

Now, to get the price, the price of an item is contained within the Item object;0710

so what we need to do is use the $this variable to say, "Give me the Item property of this particular instance of a CartItem."0715

And what that is going to do is give you the Item object of this item property that was set in our constructor.0723

And then, using this cascaded arrow syntax that we talked about before, it is going to say,0730

"From that Item object that this CartItem represents, give me the price of that."0735

It is going to multiply the two together, and it is going to return that.0740

If we go and look at our Cart class, it has a number of different methods in it.0744

It has a constructor that, as we will see, allows you to pass it a bunch of items--not CartItems, but Item objects.0747

And it will add them to its cartItems property.0756

So, let's look at the source code; we can see that it has one property called cartItems, as we had discussed.0761

And it is an associative array of CartItem objects, and the keys to that array are the item ID's.0768

Now, this Cart class has a number of different methods that have been created.0774

It has an addItem method, which allows you to add an item to a particular cart.0779

It allows you to get access to that cartItems property, which gives you an associative array0785

of all of the CartItem objects contained in this particular shopping cart.0792

It has a method called inCart that allows you to test whether a particular item is currently in the cart, based on item ID.0797

It allows you to test whether the cart is currently empty or not (meaning that there are no items in the cart).0803

And then, it also allows you to remove an item from the cart by specifying the item ID of the item you want to remove from the cart.0809

And then, here, our calcTotal method, if we look at the code for it--we can see that what it does is:0816

it gets the associative array property in this class cartItems, which is an array of all of those CartItem objects.0824

It loops over each of those items, and then it cumulatively adds to the subtotal the total due to each item.0831

So, for each CartItem object it loops over, it calls the calcItemTotal method and adds it to the subtotal.0838

Once it is done looping over all of the items, it adds the sales tax to it, rounds it, and then returns that method.0843

And that is going to be used by, for example, our checkout script, to be able to calculate the total of a cart.0849

One thing to note is that, if we look at the addItem function, what it takes is not a CartItem object, but an Item object.0861

For example, when we go to add an item on our script--let's say we are going to be adding a button to our item.php page0870

that is going to allow you to add an item to the cart--when you click on that item, it is going to go to viewCart.php.0879

And it is going to load an Item object from the database for the item that you selected, based on the item ID.0884

And then, it is going to be calling this addItem method on a shopping Cart object, and it is going to pass it this Item object.0893

Well, what is going to happen is: this method is going to test if this item is in the cart.0901

If it is not in the cart, it is going to create a new CartItem object that wraps that particular Item object.0907

And it is going to set its quantity equal to 1.0912

If it is already in the cart, what it does is goes and gets the current quantity of that item in the cart.0915

And in this case, you can see here: we are using the syntax again--the cascading arrow syntax.0922

And here, what we are doing is saying, "From this particular Cart object, give me the cartItems property (which is an array)."0927

"Give me the CartItem object that is associated with the item ID that is for this Item we are trying to add."0934

"And then, get me the quantity of it."0944

And then, what we are going to do is re-add the item to the cartItems array, but increasing the quantity by 1.0945

And so, that is how we add the item to the cart.0953

What we have done in our web application is (let's reduce the size of this a little bit): in version 10.1,0961

which is our last version of the web application, when we go to viewCart, what it does is simply outputs all of the items in a particular store.0972

And that is not typically how a shopping cart works.0983

Typically, you have an empty shopping cart, and as you add items to it, it builds it up.0985

Because we haven't had the functionality to be able to do that, our last version of it just lists all of the different items.0989

And you enter the quantity you want, and then you go to check out.0995

And there, it is going to say we need to add something.0999

In our new version, what we have done is: on each item page, we have added a button here called Add to Cart.1003

If we look at our old version, there is no button.1011

And what that does is: now, when we click on Add to Cart, it is going to go to the (I'm not sure why the lines aren't showing up;1014

there they go) viewCart page, and it is only going to add that item to our shopping cart.1025

So, now our viewCart page only has the items that are in the particular shopping cart.1030

What we have done is modified our viewCart script.1037

So, now viewCart, instead of just being, in a way, a static script that just goes through and lists (in our old version)1039

all of the different items in our particular cart, what we are going to do is pass to it an action.1048

And we can set the action to be addItem, and then we specify the item ID of the item we want to add to the cart.1055

And then, we are going to look at viewCart in a second, and we are going to see how we process that into adding an item to a cart.1061

We also can remove an item from the cart, and that is a feature that we have added to the page--we have added this Remove link.1068

And what that does is: now our viewCart page can also process a removeItem action.1075

And you specify the item ID of the item that you want to remove.1083

For example, let's go look at viewCart.php.1089

Previously, in 10.1, all we did was got all of the items in the store, using this getItems user-define function.1094

And then, we just output a row in the table for each item in the store.1104

Now, in our viewCart class, what we have done is: we allow it to take an action now, and an item ID.1109

And the item ID is going to be the item that we want to add or remove from the cart.1119

And then, in our data processing section (and this is just temporary, for this version of the app;1123

and we are going to update it later in this lesson to use cookies), we are going to create a Cart object.1128

And then, what we are going to do is: if the action of the script is to add an item, we are going to load the Item object1136

from the database, based on the item ID, and we are going to add it to the cart.1144

If it is to remove the item, we are going to use the removeItem function that we created in our Cart object to remove the item from the cart.1148

Then, we have changed the output of our Cart page.1159

Before, we would just output rows for each item that is in the store.1165

Now, what we have done is: because we have this isEmpty method, we first of all test if the cart is empty.1171

If it is empty, we just output a message that says, "Your cart is empty," and the script is done.1177

If not, what we do is output that table again.1182

But this time, we loop over all of the items that are currently in that Cart object.1186

So now, instead of just looping over all of the items in the store, we are only looping over all of the items that are in the cart.1191

When we add an item to the cart, the cart is going to be populated with an item.1196

When we call getCartItems on that object, we are going to get the associative array that contains all of those CartItem objects.1200

And then, what we are going to do is extract information from that CartItem object to output each item that we have in our shopping cart.1206

It is going to output the item's name, a link to the item's page, its price, and its quantity.1215

And then, also, we have added this new link down here, which is a link to viewCart.php1221

that has a query string that says Remove Item, and it provides the item ID of the item we want to remove.1227

And so, what that is going to do is do that for each item in our particular cart.1235

The thing that you will notice is that, in our new version, if we added Baseball Bat to the cart;1239

well, if we go and look at our viewCart script at the very beginning, we are going to see that it is going to create a new Cart object.1249

It is going to add the item to the cart, and then, when it goes down to the processing section,1256

it is going to be able to loop over that one CartItem and output a link for it.1262

So, as you can see, it is output here.1267

Now, however, if we go ahead and click viewCart again, and this time just go to viewCart1270

without any action that says Add Item, it is going to say the cart is empty.1279

And what has happened is that we lost the state of our shopping cart.1282

And that is what we are going to learn that cookies are going to provide for us.1286

They are going to allow us, in between viewing different pages of our website, to maintain the state of that shopping cart--1288

to say, "Hey, this item is in the cart, and it has a quantity of 1."1293

The reason is that, when we go to viewCart without any Add Item action,1296

when we go up here, it is going to create a new Cart object; but it is going to have no item to add to it.1304

So, our cart is going to be empty, so when it goes down here, it is going to say, "Cart is empty," and it is going to output, "Your shopping cart is empty."1307

We have no way, right now, of showing that when we go from viewCart to viewing the cart over and over again--1314

we have no way for those different HTTP requests to maintain the state of the cart.1322

And we are going to do that, using cookies.1328

The other thing that you will notice, as a result of that, is: let's say we add a basketball to our cart,1330

so now we have a basketball in our shopping cart; now, let's say that we want to go and add a DVD player.1336

Well, when we add a DVD player to our cart, we can see that the basketball is no longer in there.1342

Again, that is because we have no way of maintaining state between the different requests.1348

Each time we go to this viewCart page, it doesn't have any prior knowledge about the basketball that we have added.1353

All it knows about is the item that was currently added to the cart (in this case, it added item 1005).1360

And we are going to see how to fix that in our new application, with the use of cookies.1367

And so, as mentioned, you can see that we have added the Add to Cart buttons to our Item page.1374

And we have added Remove links to remove items from the cart.1380

One other thing is that we have also updated our checkout.php.1385

Previously, in checkout.php, what we would do is pass an items array via POST form.1392

For example, when we would submit this form on our old application, it would post (let's show an example) data to checkout.php.1399

And if we look at the POST data, we can see that it has this items array1416

that has a key which is the item ID, and then the quantity associated with each item.1421

For example, this shopping cart contains items 1001, 1002, and 1003.1427

It contains quantity 1; and so, that is how we are able to calculate our shopping cart total.1431

What we are doing is passing the information along in this array.1437

Well, in our new version, we don't have that form anymore to submit.1444

All we have is this Add to Cart button, and what that does is passes information to the viewCart page, using the action and itemID.1448

And so, what that does is: our viewCart page now only has one item.1461

So, when we go to check out, as you are going to see (and I will explain in a second why that doesn't work),1464

what is going to happen is: we are not submitting all of that information anymore.1471

We are not submitting this items associative array that contains all of the items in the store, along with their quantities.1474

Instead, what we are going to do is change checkout, so that it is going to be able to use a Cart object.1480

What is eventually going to happen is: we are going to have a cookie that is going to contain all of our shopping cart information.1486

So, when we click checkout on our viewCart form, it is going to go to the checkout page.1492

checkout.php is going to be able to read the cookie, build up a Cart object, and then be able to process the order--1498

for example, to send out an email that says, "OK, this is the order that was emailed."1504

We don't have that functionality with the cookie set up right now, so what we are temporarily doing is:1509

we have no way of passing the information from our viewCart form to our checkout.php,1513

because in our new version, viewCart.php is no longer a form.1518

It is just a link to checkout that says "action=checkout."1523

What we do is: just so we have something to show for this checkout form, we create a fake cart.1528

We are just creating a Cart object, and we are adding two items to it.1534

And then, what we are doing is: we just check to make sure that the cart is not empty, which it is not going to be, because we have added stuff to it.1539

We calculate the cart total using the calcTotal method.1544

And then, we process things as before; if the action is to complete the order, we validate the customer data,1550

and then we go ahead and email the order to the site administrator.1558

One thing to note, among many things to note, is that previously we validated the cart by using this isValidCart function that was in our utilLIB.1564

We are not going to use that anymore, because now we have this isEmpty function that is built into our Cart object1575

that will automatically tell us whether the cart is empty or not.1581

We are not going to be using calcCartTotal, because that functionality is now built into our Cart object.1583

And then, in addition, as we saw in our emailOrder function in our last version,1591

we provided it this cartItems associative array, which is that array that has keys of the items' ID's and the values of the quantity of each item.1598

We pass it the order total that was calculated by the calcCartTotal function up here.1607

We pass it the array of customer information.1617

And then, we also have to pass it information about all of the items in the database,1619

because emailOrder needs to extract the price information from the items, for example.1623

It needs the item information, so we have to pass all of that.1628

Well, in our new call to emailOrder, we only pass it two pieces of information.1633

We still pass it the customer data that was submitted on the customer form.1638

But we also now just provide one other variable called Cart, which is this Cart object that we have created up here at the beginning of the form.1642

Now, because the Cart object contains CartItem objects that have their quantity, and then it also has1651

the Item object embedded within it, that emailOrder function has all the information it needs, within that Cart object,1656

to be able to extract the price of each item, and to generate the order for the particular email.1663

If we look at our emailOrder function, we can see that now it takes a Cart object that contains all of the contents of the shopping cart.1670

And then, it still takes a Customer object that contains all of the customer data.1689

And we can see that what it does here is: now, it loops over each of the items that are contained in the cart.1694

It extracts the price information, and then the quantity information, and then outputs a line in our email--1700

whereas, in our previous version of this, it was a lot more involved in our emailOrder function.1707

What we had to do was loop over each item ID in our associative array and get the quantity for it.1716

Then, what we would have to do, if the quantity was greater than 0, would be to look up the Item1724

from the parameter allItems that was passed, which is a listing of all the items in the store,1737

extract the price information that way, and then generate this line that shows the item ID and its price.1743

Now, we extract all of that information, rather from this allItems array (that contains information about all the items in the cart),1750

simply by accessing the information that is in the cart method.1757

And so, we have used the emailOrder function.1765

The other thing is that, in our checkout.php script, previously, when we...1767

checkout.php has two sections to it: it previously received information from viewCart.php...1775

And that information would contain all of the item ID's and their quantities for items in the shopping cart.1781

And then, what it would do is allow the user to enter shipping information.1788

And then, it would proceed to a Complete Order section.1793

So, it has two actions that are processed.1797

Well, in order to be able to access all of that cart information that was passed from viewCart.php to checkout.php the first time,1800

what we had to do at the bottom of our form for the customer information was:1809

we had to loop over all of the items in the cart, and create hidden input fields1816

that would create that items array that specifies the item ID and the item quantity.1821

Well, we don't need to do that anymore, because what we are going to be doing in the next version is using cookies to contain all of that information.1828

So, we have eliminated that from our checkout.php.1834

We have also eliminated passing along the order total between the different actions of our checkout.php form,1839

because now, each time checkout.php is loaded, it has access to the Cart object, which can calculate the total each time.1845

So, we don't need to pass that along.1852

So, when we look at checkout.php in our form, we don't have any of that information here at the bottom.1854

Now, we are going to get to the point where we use cookies.1864

What we are doing is: we are going to use cookies to allow us to maintain state between adding different items to the shopping cart,1867

and also to be able to pass that information from viewCart.php to checkout.1874

We have created a user-defined function in our util library called buildCartFromCookies.1878

And what that does is: it is going to, when you go to the checkout form, for example (checkout.php),1885

look at the cookie that the user sends; it is going to see all of the information in that cookie.1892

And then, it is going to build up a Cart object from that cookie.1897

The cookies that get set when you add an item to the cart are simply going to be name/value pairs1900

where the name is the item ID and the value is the quantity.1911

For example, these would be two cookies: one cookie called 1001 that has a quantity equal to 1; and one cookie called 1002 that has a quantity 2.1916

This buildCartFromCookies method would be able to read both of these cookies, and then build a Cart object up1924

that says, "OK, this cart is going to contain the item 1001 (with the quantity 1) and the item 1002 (with the quantity 2)."1929

So then, when you go to checkout.php, it can pass that information along.1938

And then, when you enter your shipping information on checkout.php, instead of having to forward all of that information1942

hidden at the bottom of the form, that cookie is going to get passed along when you go to the completeOrder action of checkout.php.1948

Because it does that implicitly, you don't have to pass that information along.1957

checkout.php will have access to that cookie, and can then get access to all of the cart information.1962

Let's go take a look at what the last version of the store looks like.1967

So now, let's add an item to a cart; we have added a DVD player to a cart.1972

And let's say we want to add another item to a cart--we want to add a basketball.1979

Now, when we add the item to the cart, it actually maintains state.1983

The reason is that, if we look at our new viewCart.php page, what it does is checks to see if there is any cookie data.1988

If there is, it builds a cart up from that cookie; if there is not, it checks to see if the action of the form was addItem.2002

If the action of the form is addItem, and the cart is empty, then what it does is sets a cookie for that new item.2008

It sets a cookie that says, "OK, item 1001 has a quantity 1."2016

So then, now, the cookie contains information that there is item 1001 of quantity 1 within the shopping cart.2021

When we go to a different page and add another item to the store, this cookie that we have previously set here2028

is going to get sent back to viewCart.php.2034

So, when it builds this cart up from cookies again, it is going to know about that previously added item.2037

And so, what it can do is: then, it will maintain that state.2044

And so, it will contain information about the previously added cart.2049

The other thing it can do is: if the item is already in the cart (for example, Basketball), and we want to add another one to the cart,2051

we click Add to Cart again, and we can see, the quantity is updated to 2.2058

The way that works is that, if the item is already in the cart (and viewCart.php will know that,2061

because it has built up the Cart object from all the cookies that were passed to it), it can check if the item is in the cart.2070

If it is, it gets its current quantity, and then it resets the cookie for that item ID, incrementing the quantity by 1.2076

The same thing works for removeItem, except that it simply sets the time for a particular ID's cookie to a time in the past.2083

That removes that item cookie, and so, the next time you go to viewCart.php, that cookie is not going to get passed along, because it no longer exists.2094

One thing to note is that, on each of these pages, after we set the cookie,2104

that cookie does not become immediately available to the form,2109

because what we have done is built our item up from the cookie that was passed to the form originally,2113

which--if we had no items in the cart--there is going to be no cookie data.2120

When we go ahead and set the cookie, it doesn't know about that cookie until you refresh the page,2126

so we have a header function that refreshes the viewCart.php, which is going to allow it to show the updated shopping cart.2130

And that is why, when we go here, we can see that we have had an updated quantity.2139

Here, we can click on removeItem; what that is going to do...2144

And if you look down here at our Firebug console, we can see that, when we loaded this form,2147

it set a cookie for our Basketball, item 1006; and you can see that it set its quantity equal to 2.2160

You can also see that previously, when we went to this page, the web browser passed along information2169

about the current shopping cart in the form of a cookie, where it said, "item-1005 cookie is equal to 1; item-1006 cookie is equal to 1."2177

That is how it knew that there was already one in there.2186

What is going to happen is: when you go to this page, you have added a second basketball, for example.2188

It is going to set the 1006 cookie equal to 2.2193

When we refresh the page, you can see here: Firebug lets you see the refresh happening.2196

We can see that, when the page is refreshed, the new cookie has been sent, so it has that item 1005 equals 1 and item 1006 equals 2.2204

And so, that way, when it refreshes, it is able to show quantity 2 for the basketball and quantity 1 for the DVD player.2214

Now, when we remove this, what we can see in our original request is that we set a cookie, 1005,2222

and we have set it to expire in the past, so the cookie is going to be deleted.2234

So, when the page refreshes, we can see that the only cookie it has is for item 1006, which is our basketball.2238

And that is why it doesn't show up again.2245

Now, what we have also done is: on this page, we have a Checkout button that simply goes to checkout.php with the action checkout.2249

And what that does is: because this is in the same domain, it passes that cookie that contains all the information about the cart along.2258

So, checkout.php now is able to build that cart up from the cookie that it has.2264

It is able to test if the cart is not empty.2272

If it is not empty, it can calculate its total.2275

If it is completing the order, then it goes ahead and processes the customer information, and it goes ahead and emails out the order.2278

And then also, what it does is: after it is done completing the order, it goes ahead2289

and deletes all the different cookies by setting their values to a time in the past.2293

So, after we check out (I'll just put in some fake data here and go to Complete Order), we are going say that the order was successfully completed.2297

But now, when we go back to view our cart, it is going to say it is empty, because all of the cookies have been deleted that had that shopping cart data.2312

The other thing to note is that, when we have that the action is equal to checkout,2322

we are simply outputting the current total, and then we output that shipping table.2328

And again, you will notice, at the bottom here, that it doesn't contain the information2332

to forward all of the items along to checkout.php with the completeOrder action.2335

And that is because all of that information is contained in the cookie.2341

That ends today's lesson; thank you for watching Educator.com--I look forward to seeing you next time.2347

Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

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

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • 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 lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.