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

Web Application Development

The document outlines a course on web application development using PHP, covering fundamental topics such as PHP syntax, variables, data types, and control structures. It also includes advanced concepts like PHP-MySQL database interaction and the use of PHP frameworks like CakePHP and Laravel. Additionally, it provides exercises and a project to create an online voting system, emphasizing practical application of the learned skills.

Uploaded by

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

Web Application Development

The document outlines a course on web application development using PHP, covering fundamental topics such as PHP syntax, variables, data types, and control structures. It also includes advanced concepts like PHP-MySQL database interaction and the use of PHP frameworks like CakePHP and Laravel. Additionally, it provides exercises and a project to create an online voting system, emphasizing practical application of the learned skills.

Uploaded by

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

SFDWA501: WEB APPLICATION

DEVELOPMENT
Contents:
Learning Unit1: PHP Fundamentals
Performance Criterions:
1. Definition of PHP and its basics
2. Installation and configuration of PHP server
3. PHP Syntax
4. PHP variables
5. Constants
6. PHP Datatypes
7. Operators
Learning Unit 2 – Implement
PHP logic
Performance Criterions:
1. PHP ─ Decision Making/ PHP-control Structures
2. PHP ─ Loop Types
3. Arrays
4. PHP-Functions
5. File processing
6. Errors and handling exceptions
Learning Unit 3 .PHP-Web Concepts

Performance Criterions:
1. Using HTML Forms
2. Browser Redirection Displaying "File Download" Dialog Box
3. PHP ─ GET and POST Methods
4. PHP ─ File Inclusion
Learning Unit 4 –Perform PHP and MySQL Database

Performance Criterions:
1. Connection and access of MySQL database.
2. Implementation of database CRUD operations.

Learning Unit 5 – Use PHP Frameworks


Performance Criterions:
3. Introduction to frameworks.
4. Implementation of CakePHP framework
5. Implement Laravel framework
Unit1: PHP Fundamentals.
What does php stand for?
PHP is server side scripting language that is used to develop Dynamic
websites or Web applications.
PHP stand for Hypertext Pre-Processor, that earlier stood for Personal
Home Pages. PHP scripts can only be interpreted on a server that has
PHP installed. The client computers accessing the PHP scripts require a
web browser only. A PHP file contains php tags and ends with the
extension “.php”
What server side scripting mean?
a type of programming language that runs on the
server instead of the client.

What is web server?


Web server is a computer software that is used to
store and distribute webpages.
 Why Learn PHP?
There are many reasons for learning PHP.
1. PHP is one of the most widely used web programming languages and is used in many
popular content management systems such as WordPress, Drupal, and Joomla.
2. PHP is designed to be beginner-friendly and easy to learn
3. The syntax of PHP is very similar to other programming languages such as Java or c.
4. PHP is compatible with almost all servers used today (Apache, etc.)
5. PHP supports a wide range of databases
6. PHP is freely available
 PHP files
File extension and tags in order for the server to identify our PHP files and scripts, we must
save the file with the “.php” extension. Older PHP FILE EXTENSIONS INCLUDE
(.phtml, .php3, .php4, .php5, .phps.)
Topic 2. Difference between
scripting and programming
languages
• Server-side processes
Server-side processing is used to interact with
permanent storage like databases or files. The server
will also render pages to the client and process user
input. Server-side processing happens when a page is
first requested and when pages are posted back to the
server.
Your browser sends the address which you typed:
The Web server seeks if the file exists, and if this one carries an extension
recognized like a PHP application (PHP, PHP3,PHP4 for example). If it is the
case, the Web server transmits this file to PHP.
PHP analyses the file, i.e. it will analyse and execute the PHP code which
is between the <?php and ?> mark-up. If this code contains queries
towards a MySQL database, PHP sends SQL request. The database returns
wanted information to the script.
PHP continues to analyse the page, then turns over the file deprived of
PHP code to the Web server.
The Web server thus returns to the browser a file not containing more
PHP therefore containing only HTML, the web browser interprets it and
displays it.
LO 1.2 – Describe PHP Syntax, Data types, Variables,
Operators and Arrays.
Topic 1: PHP Syntax
A PHP script starts with <?php and ends with ?> :
<?php
// PHP code here
?>
PHP statement is terminated with semi colon ;
PHP uses built in function called “echo” to display outputs.
PHP scripts are embedded in HTML codes.
Example:
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo “Hello World!”;
?>
</body>
</html>

• Display:
• Hello World!
Comments in PHP

A comment in PHP code is a line that is not executed as part of the program. Its purpose is
to be read by someone who is editing the code.
PHP supports three forms or ways of expressing a comment. Comments are useful for:
· To remind yourself what you did - Most programmers have experienced coming back to
their Comments, this remind you of what you were thinking when you wrote the code
· To let others understand what you are doing - Comments let other programmers
understand each of your steps
// This is a single-line comment
# This is also a single-line comment
/*
is a multiple lines comment block that spans over more than one line
*/
Case sensitivity in PHP
In PHP, all variables are case-sensitive.
In the example below, only the first statement will display the value of the $pet
variable (because $pet, $PeT, and $PET are treated as three totally different variables):
Example
<html>
<body>
<?php
OUTPUT:
$pet=“cat”; My animal is a cat
echo “My animal is a ” . $pet . “<br>”; Undefined variable PeT
echo “My animal is a ” . $PeT . “<br>”; Undefined variable PET
echo “My animal is a ” . $PET. “<br>”;
?>
</body>
</html>
In PHP, all user-defined functions, keywords, and classes are case-
insensitive.
In the example below, all two echo statements below are legal:
Example
<html>
<body>
<?php
echo “Hello World!<br>”;
ECHO “Hello World!<br>”;
?>
-</body>
</html>
White spaces

With HTML, whitespace is ignored between PHP statements. This is to mean that there can
be one line of PHP code, then 2 or more lines of blank space before the next line of PHP
code.
Here is an elaborated example
<html>
<head>
<title>My First PHP Page</title>
</head> </body>
<body> </html>
<?php Display:
Hello World!
echo “Hello World! <br>”;
Hello World!
echo “Hello
World!”;
?>
TOPIC 2: PHP VARIABLES
A variable is a means of storing a value, such as text string “Hello World!” or the integer
value 30. A variable can then be reused throughout your code, instead of having to type
out the actual value over and over again,in other words variables can be termed as
“containers” for storing information
In PHP you define a variable with the following form:
• $variable_name = Value;
just Like in mathematics
r=1
s=2
t=r+s
Example
<?php
$txt=“Hello world”;
the letters r,s hold the numbers 1,2 respectively.
From the expression t=r+s above, we can calculate the value of t to be 3.
In PHP these letters are called variables.
Example
<?php
$r=1;
$s=2;
$t=$r+$s;
echo $t;
?>
Example
<?php
$txt=“Hello world”;
?>
• Rules for naming PHP variables
• Variables with more than one word should be separated with
underscores. $my_variable
• · A variable starts with the $ sign, followed by the name of the
variable
• · Variable names are case sensitive ($r and $R are two different
variables)
• · A variable name cannot start with a number
• · A variable name must start with a letter or the underscore
character
• · A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9,

• PHP Variables Scope
In PHP, variables can be declared anywhere in the script. The scope of a
variable is the part of the
script where the variable can be referenced/used. PHP has three different
variable scopes:
• Local
• Global
• Static
Global and Local Scope
A variable declared outside a function has a GLOBAL SCOPE and can only be
accessed outside a function:
Example
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
echo "<p>Variable x outside function is:
$x</p>"; ?>
A variable declared within a function has a LOCAL SCOPE and can only be
accessed within that
function:
Example
<?php
function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
• PHP The global Keyword
The global keyword is used to access a global variable from within a function. To do
this, use the global
keyword before the variables (inside the function):
Example
<?php
$x = 5;
$y = 10;
function yTest()
{ global $x, $y;
$y = $x + $y;
}
myTest();
echo $y; // outputs 15
• PHP The static Keyword
Normally, when a function is completed/executed, all of its variables are deleted.
However, sometimes we want a local variable NOT to be deleted. We need it for a
further job. To do this, use the static keyword when you first declare the variable:
Example
<?php function myTest() { static $x = 0; echo $x;
$x++;
}
myTest();
myTest();
myTest(); ?>
Then, each time the function is called, that variable will still have the information it
contained fromthe last time the function was called.
Note: The variable is still local to the function.
* Constants
Constants are like variables except that once they are defined they cannot
be changed or undefined. Abconstant is an identifier (name) for a simple
value. The value cannot be changed during the script. A valid constant
name starts with a letter or underscore (no $ sign before the constant
name).
Note: Unlike variables, constants are automatically global across the
entire script. Create a PHP
Constant.
To create a constant, use the define() function.
Syntax: define(name, value, case- insensitive)
Parameters:
- name: Specifies the name of the constant
- value: Specifies the value of the constant
- case-insensitive: Specifies whether the constant name should be case-
insensitive.
Default is false The example below creates a constant with a case-sensitive
name:
Example
<?php
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING; ?>
Constants are Global
Constants are automatically global and can be used across the entire
script. The example below uses a constant inside a function, even if it is
defined outside the function:
Example
<?php
define("GREETING", "Welcome to W3Schools.com!");
Function myTest() {
Echo GREETING;
}
myTest();
?>
Operators
Operators are used to perform operations on variables and values. PHP
divides the operators in the
following groups:
o Arithmetic operators
o Assignment operators
o Comparison operators
o Increment/Decrement operators
o Logical operators
o String operators
o Array operators
o Conditional Operator
PHP Arithmetic Operators
The PHP arithmetic operators are used with numeric values to perform
common arithmetical operations, such as addition, subtraction,
multiplication etc.
Exercises
1. Write a program to print “Hello World” using echo.
2. Write a program to print “Hello PHP” using a variable .
3. Write a PHP program to check whether a number is positive, negative, or zero.
4. Write a simple calculator program in PHP using switch case with two numbers Entered from the
form .
5. Write a PHP program to check if a person is eligible to vote The minimum age required to vote is
18)
6. Display the largest number among three numbers entered from HTML form.
7. Write a program to calculate Electricity bill in PHP
Conditions:
• For the first 50 units – Rs. 3.50/unit
• For the next 100 units – Rs. 4.00/unit
• For the next 100 units – Rs. 5.20/unit
• For units above 250 – Rs. 6.50/unit

5kxhLYSB7z
1. Write a PHP program to check if a person is eligible to vote The
minimum age required to vote is 18).
2. Write PHP Program to Convert Celsius to Fahrenheit.
CONDITIONS:
celsius = (fahrenheit - 32) / 5/9
fahrenheit = (celsius * 5/9) + 32
Project1
Create an online voting system with the following features:
1. A form to register voters/Users (Idno, Names, Age,
Sex, Address, Phone)
2. A form to insert candidates (Idno, Names, Age, Sex,
Address, Phone,Position) in Mysql database.
3. A page to display registered candidates where
registered voters can pic one of them.
4. A report to display sorted candidates in descending
order based their counted (summed) votes.

You might also like