Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

GMR Institute of Technology Rajam, AP: GMRIT/ADM/F-44 REV.: 00

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

GMR Institute of Technology GMRIT/ADM/F-44

REV.: 00
Rajam, AP
(An Autonomous Institution Affiliated to
JNTUGV, AP)
Cohesive Teaching – Learning Practices (CTLP)
Class 4th Sem – B. Tech Department: CSE
Course Web Coding and Development Course Code 21CS405
Prepared by Dr. Ch Sekhar
Lecture Topic PHP: Introduction, Model View Architecture (MVC), Creating PHP script,
Running PHP script, Introduction to PHP, Arrays, Functions, sending parameters
in URL, working with Forms.
Course Outcome(s) CO 4,5 Program Outcome (s) PO2,PO3
Duration 1 hour Lecture 1-6 Unit III
Pre-requisite (s) Basic Knowledge on programming, web technologies and databases

1. Objective
Demonstrate PHP server-side scripting language to develop business logic.
Make use of database connectivity to communicate database server from web server.

2. Intended Learning Outcomes (ILOs)

At the end of this session the students will able to:

• Develop PHP Script for web pages.


• Able to sending parameters using GET and POST
• Able to sending mail
• Able use Create Forms using PHP Script

3. 2D Mapping of ILOs with Knowledge Dimension and Cognitive


Learning Levels of RBT

Cognitive Learning Levels (2D)


Knowledge
Remember Understand Apply Analyze Evaluate Create
Dimension (1D)
Factual A
Conceptual B
Procedural C
Meta Cognitive D
4. Teaching Methodology

Chalk & Board, Visual Presentation

5. Evocation

Working with Database: Running SQL Queries


connecting with Databases,
Uploading Files,
PHP Sessions
Redirecting, Routing
Connecting PHP with JavaScript and Authentication

6. Deliverables
Lecture-1: PHP Introduction
PHP: PHP Hypertext Pre-processor
Programming language that is interpreted and executed on the server, Execution is done
before delivering content to the client, Contains a vast library of functionality that
programmers can harness. Executes entirely on the server, requiring no specific features
from the client. Static resources such as regular HTML are simply output to the client
from the server. Dynamic resources such as PHP scripts are processed on the server
prior to being output to the client. PHP has the capability of connecting to many
database systems making the entire process transparent to the client
• PHP is similar to C
• All scripts start with
• <?php and with with ?>
• Line separator: ; (semi-colon)
• Code block: { //code here } (brace brackets)
• White space is generally ignored (not in strings)
• Comments are created using:
o // single line quote
o /* Multiple line block quote */

Example :
<?php
$name = “GMRIT”;
$msg = “Hello world!”;
echo $name . “ says ” . $msg;
?>
Lecture-2: Model View Architecture (MVC)

Controller:
• Whenever the user sends a request for something, it always goes through
Controller.
• A controller is responsible for intercepting the request from view and passes to
the model for appropriate action.
• After the action has been taken on the data, the controller is responsible for
directly passes the appropriate view to the user.
• In graphical user interfaces, controller and view work very closely together.
Model:
• The Model object knows all about all the data that need to be displayed.
• The Model represents the application data and business rules that govern to an
update of data.
• Model is not aware about the presentation of data and How the data will be
display to the browser.
View:
• The View represents the presentation of the application.
• View object refers to the model remains same if there are any modifications in
the Business logic.
• In other words, we can say that it is the responsibility of view to maintain
consistency in its presentation and the model changes.

• MVC stands for "Model view And Controller".


• The main aim of MVC Architecture is to separate the Business logic & Application
data from the USER interface.
• Different types of Architectures are available. These are 3-tier Architecture, N-tier
Architecture, MVC Architecture, etc.
• The main advantage of Architecture is Reusability, Security and Increasing the
performance of Application.

Lecture-3: Creating PHP script, Running PHP script, Introduction to PHP


PHP can be placed directly inside HTML
E.g.
<html>
<head><title>Basic PHP page</title></head>
<body>
<h1><?php echo “Hello World!; ?></h1>
</body>
</html>

Steps to Run PHP Program


1. Installation of Server s/w (XAMPP)- First time
2. Run the Apache Server (Start )
3.Write PHP code on notepad and save file name as “fn.php”
Htdocs(folder) (c://xampp/htdocs)
4. Open browser :
localhost/test.php
View results
5. Stop Apache Server

Variable and Constants


Variables:
• Prefixed with a $
• Assign values with = operator
• Example: $name = “GMRIT”;
• No need to define type
• Variable names are case sensitive
• $author and $Author are different
Constants: Constants are special variables that cannot be changed
• Use them for named items that will not change
• Created using a define function
• define(‘A’, 1.6);
• Used without $
• $b = 5 * A;
PHP is not strictly typed
Different to JAVA where all variables are declared
A data type is either text or numeric
PHP decides what type a variable is
PHP can use variables in an appropriate way automatically
E.g.
$vat_rate = 0.175; /* VAT Rate is numeric */
echo $vat_rate * 100 . “%”; //outputs “17.5%”
$vat_rate is converted to a string for the purpose of the echo statement
Object, Array and unknown also exist as types, Be aware of them but we shall not
explore them today

Lecture-4: Arrays, Functions


• Numeric Arrays
• Associative Arrays
• Multidimensional Arrays

Numeric Array
These arrays can store numbers, strings and any object but their index will be
prepresented by numbers. By default array index starts from zero.
/* First method to create array. */
$numbers = array( 1, 2, 3, 4, 5);

/* Second method to create array. */


$numbers[0] = "one";
$numbers[1] = "two";

Associative Arrays:
• The associative arrays are very similar to numeric arrays in term of functionality
but they are different in terms of their index.
• Associative array will have their index as string so that you can establish a strong
association between key and values.

/* First method to associate create array. */


$salaries = array(“ABC” => 2000, “XYZ" => 1000,“A1" => 500
);
/* Second method to create array. */
$salaries[‘ABC'] = “2000";
$salaries[‘A1'] = “500";

Multidimensional Arrays
A multi-dimensional array each element in the main array can also be an array. And
each element in the sub-array can be an array, and so on. Values in the multi-
dimensional array are accessed using multiple index.
$marks = array(
“5D1" => array (“S1" => 35,“S2" => 30,“S3" => 39),
“5D2" => array (“S1" => 30,“S2" => 20,“S3" => 30),
“5D3" => array (“S1" => 38,“S2" => 40,“S3" => 37)
);
Functions :
PHP function is a piece of code that can be reused many times. It can take input as
argument list and return value. There are thousands of built-in functions in PHP.
Advantage of PHP Functions
Code Reusability: PHP functions are defined only once and can be invoked many times,
like in other programming languages.

Less Code: It saves a lot of code because you don't need to write the logic many times.
By the use of function, you can write the logic only once and reuse it.

We can declare and call user-defined functions easily. Let's see the syntax to declare
user-defined functions.

Syntax
function functionname(){
//code to be executed
}

Lecture-5: sending parameters in URL


The parameters from a URL string can be retrieved in PHP using parse_url() and
parse_str() functions.

Note: Page URL and the parameters are separated by the ? character.

parse_url() Function: The parse_url() function is used to return the components of a


URL by parsing it. It parse an URL and return an associative array which contains its
various components.
parse_url( $url, $component = -1 )
parse_str() Function: The parse_str() function is used to parse a query string into
variables. The string passed to this function for parsing is in the format of a query string
passed via a URL.

Syntax:

parse_str( $string, $array )


Approach: Parse the URL string using parse_url() function which will return an
associative array that contains its (passed URL) various components. The query of the
array returned by parse_url() function which contains a query string of URL.

Lecture-6: WORKING WITH FORMS.

When the user fills out the form above and clicks the submit button, the form data is sent for
processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST
method.
To display the submitted data you could simply echo all the variables.
The "welcome.php" looks like this:

<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

<html>
<body>
<form action="welcome_get.php" method="GET">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

Keywords
• PHP, url, functions, arrays, associate arrays.

Sample Questions

Remember
1. Explain features of PHP
2. Explain types of arrays
3. Write syntax to create function in php

Understand
1. Explain about control syntax in php with examples
2. Explain associate and multi dimension arrays.

Apply

1. Design and Deploying the online exam portal using php

Stimulating Question (s)

Design a flask based Website and deploys in real time

Mind Map
Student Summary

At the end of this session, the facilitator (Teacher) shall randomly pic-up few students to
summarize the deliverables

Reading Materials
1. An Introduction to Web Design + Programming, Paul S.Wang, India Edition
2. Web Coding Development All In One for Dummies, Paul McFedries, Wiley.

Scope for Mini Project


Yes

You might also like