0% found this document useful (0 votes)
7 views

Module 2 - How To Create A Simple Dynamic Web Application

Module 2

Uploaded by

karanaffiliate26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Module 2 - How To Create A Simple Dynamic Web Application

Module 2

Uploaded by

karanaffiliate26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Module 2: How to Create a Simple Dynamic

Web Application
Overview

(Kobu Agency, 2018)

In our last module, we have seen web architecture components, and how a web server responds with static and dynamic contents.
We have also seen how web applications use the server-side scripts such as PHP that run on the server to provide rich and dynamic
web responses to the clients.

As you know, PHP is the most popular server-side scripting language for web application development. It’s free and open source. You
have already seen how to run and edit PHP applications. In this module, you will learn how to code simple PHP applications, and
develop basic PHP skills. Before starting this module, make sure you have completed the exercises of Module 1.

Learning Outcomes
By the end of this module, you should be able to:

Code a PHP application to get data from a request.

Describe how to work with data using PHP.

Find answers to questions in the PHP documentation.

Code control statements.

Below is a more detailed version of the learning outcomes.

Knowledge

Explain how PHP is embedded within an HTML document.

Distinguish between PHP statements and comments.

Describe these PHP data types: integer, double, Boolean, and string.

List the rules for creating a PHP variable name.

Describe the code for declaring a variable and assigning a value to it.

Describe the use of the built-in $_GET and $_POST arrays.

Describe the use of the echo statement.

Describe the rules for evaluating an arithmetic expression, including order of precedence and the use of parentheses

Describe the use of these built-in functions: intdiv(), number_format(), date(), isset(), is_numeric(), htmlspecialchars(),
filter_input(), include(), and require().
Describe how an XSS attack works and how to protect against this type of attack.

Describe the rules for evaluating a conditional expression, including order of precedence and the use of parentheses.

Describe the flow of control of an if, while, or for statement.


Applied Skills

Create variables with valid names and assign values to them.

Use literals and concatenating strings.

Use the built-in $_GET and $_POST arrays.

Use echo statements to display data on a page.

Code string and numeric expressions.

Use compound assignment operators.

Use the built-in intdiv(), number_format(), date(), isset(), empty(), and is_numeric() functions.

Use the htmlspecialchars() function to escape special characters on a page.

Use the filter_input() function to filter input from the $_GET and $_POST arrays.

Code conditional expressions.

Code if, while, and for statements.

Use built-in functions like include() and require() to pass control to another page.

Assessments
Assignment 1: Dynamic Web Application Using PHP (10%)

Activity Checklist
The following is a list of ungraded activities designed to help you to be successful in the graded activities.

Activity 2.1: Pre-Test

Activity 2.2: Basic PHP Skills

Activity 2.3: Getting Data from a Request

Activity 2.4: How to Work with the Data

Activity 2.5: Reflecting on the Product Discount Application

Activity 2.6: Control Statement in PHP

Activity 2.7: How to Work with Dates and Arrays in PHP

Activity 2.8: Example Application—“Future Value Application”

Activity 2.9: How to Use the PHP Documentation

Activity 2.10: Post-Test

Activity 2.11: Practice, Practice, and More Practice


Recall Prior Learning
At this point, you should have a good understanding of how dynamic web application works, and the role of PHP. In this module, we
are going learn how to code in PHP. Therefore, it’s important that you should read and understand the components of web application
development by completing Module 1 as well as finishing all the exercises of Module 1 before starting this module. Most importantly,
review: (1) client-server architecture, (2) back-end and front-end technologies, and (3) how to run and edit PHP application.
Activities
Activity 2.1: Pre-Test
Please take the Module 2 Practice Test before you start this module. This test is self-marked and consists of 10 questions. It allows
multiple trials, and you can resume the quiz at any time once you have started it. After taking this quiz, and on a scale of one to five,
how could you rate your knowledge about web application development?

Module 2 Practice Test


Activity 2.2: Basic PHP Skills
In Module 1, you have seen the components of a typical PHP application. In this module, you will start with some basic PHP skills
that you need to learn before you can actually create an application that stores data. Please read “Basic PHP Skills” in Chapter 2
from the textbook and answer the following questions.

1. What are the datatypes available in PHP? List all of them.

Show Answer

2. Give an example of an invalid variable name in PHP.

Show Answer

Activity 2.3: Getting Data from a Request


One of the most important and frequent tasks that you need to perform in a web application is to get the data sent by a client as part
of the HTTP request. Your application needs to use and operate on these data. So, it is very important to understand and learn how
to get that data from the HTTP request and store it in your PHP variables. That is what you will learn by reading the “How to Get Data
from a Request” in Chapter 2 from your textbook. After reading this section, answer the following questions:

1. Which PHP variable stores the data of HTML’s GET method? What is the type of the variable?

Show Answer

2. What is superglobal variable and what does it mean? Give an example of superglobal variable in PHP.

Show Answer

3. When should you use GET and POST methods?

Show Answer

Activity 2.4: How to Work with the Data


Now that you have gathered the basic skills for retrieving data from an HTTP request and storing it in a variable, you’re ready to learn
how to work with that data by reading the “How to Work with Data” in Chapter 2 from your textbook. At this point, you should also
learn some more details and other ways of how to work with different data in PHP by reading the “Chapter 7: How to Work with Form
Data” and “Chapter 9: How to Work with Strings and Numbers” from the textbook.

After reading this section, answer the following questions:

1. True or false: There is absolutely no difference between single or double quotation marks to code a string in PHP.

Show Answer

2. Which PHP statement can you use to send data back to the browser?

Show Answer

3. What is the meaning of “.=” compound assignment operator?


Show Answer
4. Determine what would be final value of the $subtotal variable after executing the following statements.

$subtotal = 2.68;

$subtotal /= 2;

$subtotal--;

Show Answer

5. What is the benefit of using the filter_input() function?

Show Answer

Activity 2.5: Reflecting on the Product Discount Application


By this point, you should have developed a basic skill for coding PHP applications. It’s now a good time to reflect back on the Product
Discount application from Module 1. You can also find it in your textbook in “The Product Discount Application” in Chapter 2.

Give particular attention to the PHP file and notice how the data were retrieved from the form using the $_GET variable, how the
discount and discounted price were calculated, and how to apply formatting in currency and per cent amount.

Activity 2.6: Control Statement in PHP


If you have prior experience with other programming languages, then you already know how the control statement allows you to
control the flow of statement execution in an application. PHP is no different from other programming languages. In this section, you
will learn how to code control statements in PHP. Read the section “How to Code Control Statements” in Chapter 2 and “Chapter 8:
How to Code Control Statements” from the textbook.

After reading this section, answer the following questions:

1. What would the following statement return?

1 === TRUE

Show Answer

2. A ________ joins two or more conditional expressions using the logical operators.

Show Answer

3. What is the difference between built-in functions “include” and “require” methods?

Show Answer

Activity 2.7: How to Work with Dates and Arrays in PHP


In many web applications, you may have to use dates and some collection of data. Therefore, it’s crucial to understand how PHP
handles date and array in PHP by reading “Chapter 10: How to Work with Dates,” and “Chapter 11: How to Create and Use Arrays”
from the textbook.

Activity 2.8: Example Application—“Future Value Application”


At this point, you should have learned a complete set of PHP skills that you can use to build applications of your own. To give you a
head start, examine the “The Future Value Application” from Chapter 2 of the textbook.

Notice how multiple PHP files are working together in an application, and when the user clicks on the Calculate button on the first
page, the data is submitted to the “display_results.php” file via the POST method.
Activity 2.9: How to Use the PHP Documentation
Whenever you learn a new programming language, it’s crucial to know how to access its documentation, because if you encounter a
problem that you can’t figure out based on what you already know, you can consult the documentation for more information. The best
place from where you should read the documentation is the official PHP manual page.

The official PHP manual site is the most up to date and accurate source of information for PHP programming language. So,
whenever you have any doubt on any functions or syntax of PHP, you should consult the official page.

The section “How to Use the PHP Documentation” in Chapter 2 of your textbook also describes how to use the official PHP
documentation page.

Activity 2.10: Post-Test


At this point, please take the Module 2 Practice Test again to identify the important concepts covered in the module.

Module 2 Practice Test


Activity 2.11: Practice, Practice, and More Practice
To reinforce the concepts that we have learned in this module, you should complete the following exercises from the textbook.

Exercise 2-1 Build the Product Discount application

Exercise 2-2 Enhance the Future Value application

Exercise 7-2 Enhance the Future Value application

Exercise 8-1 Use if and switch statements

Exercise 8-2 Use loops

Exercise 9-1 Write code that works with strings

Exercise 9-2 Write code that works with numbers

Exercise 10-1 Write code that works with dates

Exercise 11-1 Work with the arrays of the Task List Manager application

Each exercise provides direction to the required files. You can also download these files, including the exercise startup files, the
exercise solutions, and the book-applications.

Exercise Files, Solutions and Book Applications


Assessment
Note
Before you start developing web applications, you need to set up and configure the required software for the web application
environment on your machine. See Activity 1.1: Configure Web Application Development Environment in Module 1 for more
information.

Assignment 1: Dynamic Web Application Using PHP (10%)


In Assignment 1, you will address six questions that re-enforce the PHP concepts discussed in Module 2.

Assignment 1: Dynamic Web Application Using PHP (10%)


Summary
In this module, you learned how to create a simple dynamic web application, including the basics of how to code in PHP. In the next
module, you will be introduced to relational databases and MySQL

You might also like