Matthew M.

Matthew M.

Accessing Form Data in PHP

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
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

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Lecture Comments (8)

0 answers

Post by Kitt Parker on January 7, 2015

The curly brace method for multidimensional arrays throws me off a bit.  I feel like it breaks consistency and thus is not ideal.  I would think the ideal solution would have been to just call a multi-dimensional array value with the same syntax.  I wonder why it turned out this way.

0 answers

Post by Anand Richard on July 8, 2013

I keep getting merely the echo'ed statements and not the $_GET array values at all. I have copied the code exactly as it is but no results.

0 answers

Post by eoctech21 on May 22, 2013

Is it possible to submit the form to it's own unique page? To somehow change the action in <form method="get" action="test.php"> and have it be a randomly generated number, similar to how uploading a YouTube video works.

I don't want the information I store in the form to be lost as soon as I get off the page. Users should be able to just copy/paste the link and see what I put.

0 answers

Post by Dixon Kavanaugh on April 25, 2013

Hi,

Jut a point of clarification for my own understanding. In the homework solutions folder step-4 you have given the names "accountIndexed" & "accountAssoc" - these are names you are using not required syntax, correct?

Thanks!!

3 answers

Last reply by: Matthew M.
Wed Apr 11, 2012 3:41 PM

Post by David L on March 1, 2012

Hello, these videos are great. I have a question.

I wanted to test the syntax for "Outputting arrays in a string". 25:29 in the video.

My code:

<?php
$_GET['name'] = 'john';
echo "his name is $_GET[name];
?>

It yields this error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING ... on Line 3.




I have tried changing line 3 to:
echo "his name is $_GET['name']";

as well as changed the variable from $_GET to just $get.

Why is this? I am on a Mac and using XAMPP and the version PHP is 5.3.1 so I am not sure that is the reason for the error. Old version maybe?

Accessing Form Data in PHP

  • $_GET is a pre-defined associative array created by PHP that holds all input data submitted to a PHP script via the GET method.
  • One can have arrays created in $_GET by using a square-bracket syntax when specifying the name attribute for form input controls. For example:
    • <input type="text" name="address[city]" />
  • Variable interpolation in double-quoted strings can be used to output the values of both indexed and associative arrays. There is both a 'simple' and 'complex' syntax available for this.
  • Multi-dimensional array values in double-quoted strings should be output using the complex, or 'curly brace', syntax.
  • Additional Resources:

Accessing Form Data in PHP

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
  • $_GET Array 0:48
    • $_GET Array
    • Accessing the Value of a Name/Value Pair Submitted Via GET
  • Name Form Example 2:54
    • Name Form and the $_GET Array
  • Using Arrays with Input Controls 6:34
    • Using Arrays with Input Controls
    • Common Example
  • Indexed Array Form Example 8:16
    • Indexed Array Form Example
  • Associative Arrays with Input Controls 10:14
    • Associative Arrays with Input Controls
  • Associative Arrays Example 11:41
    • Associative Arrays Example
  • Echo Form Example 15:18
    • Echo Form Example
  • Outputting Arrays In String 23:42
    • Variable Interpolation
    • Outputting a Value in an Indexed Array Within a String
    • Simple' Syntax, 'Complex' Syntax, and 'Curly Brace' Syntax
  • Outputting Arrays In String Example 26:25
    • Outputting Arrays In String Example
  • Homework Challenge 29:39
    • Homework Challenge

Transcription: Accessing Form Data in PHP

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

In today's lesson, we are going to be expanding the material from last lesson, where we learned how to input data to a script.0004

Today, we are going to learn how to access that data from a PHP script.0012

Specifically, we are going to learn about what is known as the $_get array, which is how you access input that was passed to a script by the GET method.0018

We are going to talk about how we can use input controls to submit information to PHP in the form of an array.0032

We are also going to talk about how to output array values within strings, using variable interpolation.0040

What is the get array, is it is called? The $_get array is an associative array that is created by PHP every time a PHP page is requested by the GET method.0050

What it does is: it goes out, and it extracts any name/value pairs that were appended as part of the query string of the URL.0065

And it puts them into this array: basically, what it does is: for each name/value pair that is appended to the URL,0073

it creates a key, and it sets the key equal to the name of each name/value pair,0081

and it sets the value associated with that key equal to the value of the name/value pair.0089

For example, if we have a text field, and we have it set at the name firstName,0095

when you submit a form containing that text field, whatever value is assigned to that text field is going to be associated with firstName.0104

So, it's going to be firstName=matthew as part of the query string.0114

What is going to happen is: PHP is going to go and create this get array that is always available in your PHP files.0119

And it is going to create a key called firstName, and it is going to associate with that key the value that you submitted.0128

So essentially, what it is going to be doing--if you remember from our lesson on arrays...0135

So, if we submitted...in the text field, if we type the text value, essentially what PHP is going to do0157

is create a key, a name firstName in the get array and assign it the value value.0163

Let's take a look at a script, or a basic HTML file, that shows how some of this works.0176

What we have done is: we have created a basic HTML form that has one text field in it, kind of like we just talked about.0186

And what it allows you to do is submit your name--and actually, before we do that, let's look at the HTML code.0193

It is a form that uses the get method, because that is what we have been using.0202

The action, if you will notice, is something different from what we talked about in the last lesson; it's actually a separate file.0207

In this case, it's a PHP file; and now we are going to learn how to access that information.0212

So, this PHP file, processNameForm.php, is going to be able to use that information that we provide in a text field.0218

If we go ahead and I submit my name, it is going to go to processNameForm.php,0228

and as you can see, it appended the name/value pair person=matthew to the URL.0237

And what I have done is actually just used the print_r function to output what the GET associative array looks like.0242

And, as you can see, the GET array contains one key and one value, and the key is person, and the value is matthew.0251

And if we actually go back and look at our HTML, we can see that, on the input tag for our text field, the name is person.0262

And so, person directly corresponds with the person key in the GET array.0271

Let's go look at the code that processes the form that processes the name.0282

It's called processNameForm.php, and basically, we have some PHP code here at the beginning that outputs what we had just showed you.0286

It just outputs the contents of the GET array.0295

Let's go ahead and delete that and do something a little more useful.0301

I've commented out a section of code here that is going to output a Thank You message, and it is going to quote the person's name listed on the form.0304

I have to get rid of these comment tags.0316

If we go back to our page and try a different name and click Submit, now what we have done is output a message0324

that says "Thank you," with the name submitted, Joe Smith, "for entering your name; you now have accessed PHP data for the first time.0334

"The sky is the limit," and I created a little link to return to the form.0341

Now, if we go back and look at the code here, all it did was: it has a couple of echo statements that echo some HTML code,0344

and then, one echo statement that references the GET array,0353

and because the name of the text field which we submitted with the form was called person, we denote the person key and the GET array.0358

What that is going to do is go to the GET array, get the value associated with the person key (which in our case, I think, was Joe Smith),0369

and then it is going to output it--so it is basically going to add it to the output string.0377

That is an introduction into how GET works with simple name/value pairs.0382

Things can get a little more advanced: PHP has a nice feature,0395

in that it allows you to create arrays in the GET associative array that it provides for you.0399

The way you do that is: you provide, in the name attribute of different input elements, a name with opening/closing square brackets.0408

When you do that, and when you submit the form, what that tells PHP is that any name/value pair that has the name items,0422

for example, item...this one here...equals 1001--it is going to create a key called items, and then it is going to associate with that key an array.0433

And for every name/value pair that has the name items, it is going to add that value to that array.0450

A typical use of this is in select dropdown menus, where you can select multiple items from the list.0458

And the way that you access the values within your PHP script is: as we learned in the multidimensional array section of the array lesson,0469

you specify GET, and then, in this case, items; so that is saying "Get me the array associated with the key items."0481

And then, you specify a numeric index to access the different values in the array.0489

If we go and look at another form called indexArrayForm.html, we can see, we have a select box where we can select multiple things.0497

The way you do that is with the control key--Ctrl+click.0508

We can submit it, and what you can see here is: again, to demonstrate how the GET array is formed, you can see that0513

(I'll blow it up a little bit), using the print_r statement, the GET array contains one key/value pair.0525

The key is named items, and it contains two elements--1001 and 3001--which are the ID's of the product that we selected.0533

They have the indexes 0 and 1.0544

Now, if we actually go and look at the HTML for the form, we can see that we have declared, as in the slide, a select dropdown menu,0546

given it the name items with the opening and closing square bracket, and then we have simply added option tags with different values.0557

What is going to happen is: when you submit that form, the browser is going to append to the URL (because we are using the GET method in this form)0567

items= , and then it is going to list the item ID of each item we chose from the list.0578

So, if we go back and look at when we submitted the form, you can see, in the top URL here, there is items listed twice in the query string--0584

items=1001 and items=3001, and because there are brackets associated with those items, PHP is going to know that0597

that is going to refer to an array, and it's going to create an array with those values.0604

We just saw how PHP--you can use indexed arrays, or numeric arrays, in your forms; you can also use associative arrays.0616

For example, we can have two text input boxes, or text fields, and we can assign them a name like this,0625

where the array would be called person, and the key of the array would be called first.0637

We can also do it for another one with last.0643

So basically, what this is going to do is: when you submit this form, PHP is going to parse the URL.0647

It is going to create a key in the GET array named person, to which it is going to associate0653

an associative array with the key first and the key last, along with whatever values were submitted to those corresponding text boxes.0663

One thing to note is that, unlike in PHP code (when we reference something in an associative array, you enclose it in quotation marks),0676

when you do this in HTML, you don't do that; you leave out the quotation marks; and PHP will know how to handle that.0691

Let's take a look at how associative arrays work.0701

We have a form associativeArrayForm.html, and it is going to allow us to input a first and last name.0713

We submit the form; we are going to do the print_r again on the GET array, and it is going to show you that the GET array0722

contains one key/value pair; the first key, or the only key, is named person, and it is associated with a data value,0733

which is an associative array that has two keys, first and last, and first is set to matthew; last is set to machaj,0742

which were the first and last names that were entered into the text field.0750

And so, if we go and look at the HTML form itself, we can see that we have two text input fields that we created.0757

And using the square bracket syntax, we typed person[first] to correspond to the firstName in the person array,0766

and then, this one right here corresponds to the lastName in the person array.0780

So, these are directly correlated to these in the GET array.0783

Now, if we go and look at the code...let's get rid of the print_r statement, and we can do something a little more useful than that.0793

This is going to demonstrate how to access the different values in the GET array that created an associative array called person.0805

One way we can do that is: we can declare a variable called person and set it equal to0820

the value associated with the person key in the GET associative array, which, as we saw in our case, is this array here.0827

It contains a first key and a last key, and then the values associated with them.0836

And then, what we do is: we just create an output message to output the person's name, giving the welcome message.0841

And so, we have a couple of echo statements; here is just a welcome statement.0848

And then, because this is an associative array, we use the square bracket syntax for associative arrays0852

to access the name associated with the key first, which was what was entered in the first text box.0858

And then, we also output the last name, which we access by the last key.0865

And if we go ahead and load this in the browser--let's try a different name...oh, I guess I didn't save it; let's try one more time...0871

You can see, it says Welcome, and then John Smith; and this John Smith...this is the first name0895

that was outputted from the person associative array, and Smith was the last name that is part of the person array, as you can see here.0901

So, I have also created another script that shows more form input controls and how they work, similar to in the last lesson.0915

We go to echoForm.html (shrink this down a little bit): this is similar to a form we saw in the last lecture.0928

It has a text field, a password field, a radio button, a check box, a multiple selection box, text field, hidden field, and so forth.0938

If we go and put in some information like username, password, male, are you married, and then select a couple of our favorite RGB colors,0951

enter a comment, and click Submit...we are going to use the print_r function again on the GET array,0963

and that is going to show you what was passed on by the GET method.0974

We can see that, in the GET array, there was a text field named username, and the value associated with it was username.0979

There is a password field, a text field (I misspelled password) that is associated with the value password.0986

Additionally, on this form, for the two questions sex and the check box "Are you married?" I have created an associative array0996

called personal info, and given it two keys, sex and married.1012

And if we go and look at the HTML for the form, we can see that, for the radio buttons, we have declared the name personalInfo,1019

and then put in square brackets the name of the key we want to assign that value to--in this case, sex.1036

And then, if we look down here at the married check box, we have assigned it the name personalInfo as well,1043

which means to put it in the same associative array as this up here, except it's going to use the key married.1050

And so, that is why, when we submit the form, it creates this personalInfo array.1059

Additionally, we have also created a numerically indexed array called favColors,1065

and what that was for, was for when you had the option to select multiple favorite RGB colors.1069

And so, what happens in that one is: as we had seen in the indexed array example before, for the select tag,1079

we give it the name favColors, and then follow it by the opening/closing square brackets,1089

which tells PHP, when it finds any key/value pairs that have the name favColors, that they are going to be part of one array.1094

Because no index is specified, it is going to be a numerically indexed array.1102

And then, any options that are selected are added to this array.1105

So, in this case (let's go ahead and try again) we'll select blue and green, and we submit it.1109

We can see that it has added green and blue to the favColors array; and they have the index 0 and 1.1116

Additionally, the large text area Comments has the string that we included associated with it.1124

And also, down here, you can see, it has the value of a hidden tag.1131

We had a hidden input tag in our HTML; you go down to the bottom and look at it: input type, and we called it hidden.1136

We assigned it the name hidden, and then we gave it the value IP 192.168.1.1,1147

which may be some data that is of use to our script, but we don't necessarily need the user to see.1154

And so, when we loaded up the form and output the GET array, we can see that that hidden value,1160

even though it wasn't actually submitted by the user, does get put into the GET array.1169

Let's look again at the the processEchoForm.php.1184

What it does is: as the other files have done, it just uses a print_r statement to output the contents of GET.1193

But we can use it, again, to do something more useful.1201

In this case, we are just going to simply echo (and that is why it is called an echo form) all of the data that was submitted by the form.1206

As you can see here, we have a bunch of echo statements, in which we create an unordered list,1213

and for each list element, we output the value associated with each input field.1221

For example, for the username text box, we are going to use the GET array.1228

Access the GET array; give it the key username, which was the name in echoForm.html, which was associated with the username text field.1232

And we do that for all of the different input boxes; so we do it for password...1248

Additionally, as you can see down here, we had mentioned that we created an associative array, personalInfo, with the keys sex and married.1253

And as you can see here, the way we access that data from the GET array is using the double square bracket syntax used for multidimensional arrays.1262

And to review that again, what this first part here says is: Give me the value associated with the personalInfo key in the GET array.1272

That happens to be an associative array, and it contains different keys, and one of them is sex.1283

And so, this says to get the value associated with the key sex.1289

This one does the same thing, except it does "Get the value associated with the key married."1294

Now, down here, what we have done is: for the favorite colors, we look back at the HTML; we named it favColors with an opening and closing bracket,1300

which is going to create an indexed array in the GET array; PHP is going to do that automatically.1316

And what we can do is: we can output, in this case, the first color selected.1324

The first item in an indexed array always begins with the 0 index, if you remember.1328

And because this is a multidimensional array, we use the square brackets index again.1335

And this, again, says, "Give me the value in the GET array associated with the key favColors, which is itself going to be an array."1339

"And then, give me the first element in that, which depends on what we selected in the text box."1346

This just outputs the comments and hidden (remove this last comment and save).1354

If we reload the form, and let's pick red and green this time...female...password...New comment, and hit Submit, we can see the formatted output.1359

It says the username we entered was username; password was pawd; it outputs the sex of the user and whether they are married or not.1380

It outputs the first color selected, which in this case was red.1391

We change it, and then green and blue...it is going to output green, because green will be the first element added to the favColors array.1395

And then, you can see, it outputs, in a prettier format, the content of the comment input element and what was the value of the hidden input element.1407

So now, I want to continue on a topic that we have covered in a previous lecture, about variable interpolation.1423

And in this case, we are going to talk about how to output array variables within a double-quoted string.1428

We know that we can do that for, for example, integer, float, and other string variables.1434

We can include them within the double quotes of another string, and the echo statement will go ahead and replace the variable with its value.1439

But we can also do that for arrays; this is quite useful.1446

There is particular syntax for that: for indexed arrays, such as here, what you do is:1450

you access the value of the array, simply as you would in your PHP code.1467

You simply type the variable name, which is a dollar sign followed by the variable name,1471

and then square brackets with the integer index enclosed in between them.1477

And what that is going to do is replace this variable value with whatever the second value is in this indexed array.1482

That is pretty intuitive, because it's exactly the same way you would access it in PHP code.1494

Now, for associative arrays, it's a little bit different.1501

It's similar syntax, except that, if you notice, there are no quotes around the key name.1505

So, you access it in the same way you would in a PHP file, except you leave the quotes out.1512

This is known as the simple syntax; there is also a complex, or curly brace, syntax, which is used for outputting more complex things within strings.1520

And as we go through the course, we will find different, more complex things--for example, like object values and function output--to output.1530

But, if you want to use the quotes, and you feel more comfortable that way, you can enclose everything in curly braces and add the quotes.1540

Now, this curly brace syntax is also used for complex things--one of those being if you want to output a multidimensional array.1550

Let's say assoc was a multidimensional array; this is how you would specify that in your code.1566

Let's go take a look back at the process echoForm.php, and put some of this into action.1587

What you will see is: it is going to turn this...right now, we have three echo statements to output1594

a list item that says username, and then outputting the username that was provided.1599

We can actually turn these three lines of code into one, and that is through variable interpolation.1603

Because this is an associative array, we go ahead and remove the quotation marks.1611

And if we go and load this page up, and submit it, you can see that it outputs the username, just as we expected it to before.1621

As you can see, it definitely makes the code a little easier to read--less lines to accomplish the same thing--and it's pretty intuitive.1641

You know that it is going to replace this GET[username] with whatever value is in the GET array, associated with the key username.1649

I'm just going to go ahead and quickly do this for these other values.1658

This is a multidimensional array, so we have to use, as mentioned, this special curly brace syntax.1670

And with curly brace syntax, we leave the quotation marks in.1675

The same goes for multidimensional arrays containing one dimension, or one of the arrays, as an indexed array.1696

I'm sorry, I forgot up here to get rid of the single quotes.1728

And so now, we have gone and changed all of those lines, which was three lines per list item, into one line.1731

And when we go ahead and load this page up again, it is going to output the same information,1739

but we are making use of variable interpolation with associative arrays and indexed arrays.1744

Let's go ahead and...if we go ahead and submit it, we can see that everything outputs as we had expected from before.1752

That is how to make use of variable interpolation for arrays.1771

And you find that you will be using that a lot, throughout your PHP code.1775

For today's homework challenge, I am going to have you get practice with using the GET array.1781

You are going to be using it all the time in your PHP scripts, because you are constantly interacting with the user and receiving form input.1786

I want to have you create a regular HTML file that contains an HTML form, and just put it in the lecture_12 directory.1793

And have the form contain all of these different input controls.1802

And then, create another file, a PHP script, that is just basically going to echo the data submitted by the HTML form.1809

And make sure that, when you create this PHP script, you set the action attribute of the form element to whatever you named your HTML file up here.1818

And so...actually, the form element is going to be in the HTML file; make sure that you set the action1832

equal to the name of the PHP script that is going to be echoing the data.1837

Then, what I want you to do is experiment with outputting and accessing values of the GET array.1843

So, use non-array names for your controls--for example, like name=text1; and just practice outputting those different values from your PHP script.1849

Then, change some of the controls, so that they have array names, like we talked about.1867

Maybe you will have a select dropdown box that will have the name...maybe it's states; and create it like that.1870

And do that for both the indexed array and the associative array variety, and practice outputting it.1884

And, when you output the value of the GET array, practice using what we learned in the last slide,1889

which was variable interpolation that you can use with double-quoted strings to output the values of arrays.1897

Experiment with both the simple and complex syntax.1904

The simple syntax is just the variable name, and the complex syntax actually uses the curly braces around it.1908

That ends today's lesson; thank you for watching Educator.com, and I look forward to seeing you next lesson.1916

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.