GMR Institute of Technology Rajam, AP: GMRIT/ADM/F-44 REV.: 00
GMR Institute of Technology Rajam, AP: GMRIT/ADM/F-44 REV.: 00
GMR Institute of Technology Rajam, AP: GMRIT/ADM/F-44 REV.: 00
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.
5. Evocation
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.
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);
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.
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
}
Note: Page URL and the parameters are separated by the ? character.
Syntax:
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
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.