Web Technology II PHP JS
Web Technology II PHP JS
01 Introduction
Computer Science
Web Technology
▪ Application software to
explore World Wide Web.
▪ Provides an interface
between server and client.
▪ Displays text, data, pictures,
animation and video on the
internet.
Web Server
Computer Science
PHP (Hypertext Preprocessor)
Computer Science
Basic Syntax of PHP
Computer Science
Comments in PHP
Computer Science
Variables in PHP
▪ Containers for storing data.
▪ Used to hold data in a computer program that may
be referenced and changed.
▪ A variable starts with the $ sign, followed by the
name of the variable.
▪ PHP has no command for declaring a variable. The
variable is created when a value is assigned to it.
Variables in PHP
Computer Science
Echo and Print
Computer Science
Data Types in PHP
▪ Variables can store data of different types.
▪ Different data types can do different things.
▪ PHP supports following data types:
○ String ○ Array
○ Integer ○ Object
○ Float (also called double) ○ Null
○ Boolean ○ Resource
PHP String
▪ A string is a sequence of characters.
▪ Can be any text inside quotes.
PHP Integer
▪ A non-decimal number.
▪ 32 bit system: -2147483648 to
2147483647
▪ Must have at least one digit.
▪ Must not have a decimal point.
▪ Can be either positive or negative.
▪ var_dump() returns data type and
value.
PHP Float
▪ A number with a decimal point or a number in
exponential form.
▪ Floating point or Fractional number.
PHP Boolean
Computer Science
Constants
Computer Science
Operators
Computer Science
Control Statement
▪ Conditional statements that execute a block of
statements if the condition is correct.
▪ The statement inside the conditional block will not
execute unless the condition is satisfied.
○ If statement
○ Nested if statements
○ If…else statement
○ If…elseif…else statement
○ Switch statement
IF Statement
▪ Executes some code if one condition is true.
▪ Used to execute the block of code exist inside the if
statement only.
▪ Syntax:
IF Statement Example
Nested IF Statement
▪ Contains the ‘if’ block inside another ‘if’ block.
▪ The inner ‘if’ statement executes only when
specified condition in outer ‘if’ statement is true.
▪ Syntax: if (condition) {
//code to be executed if condition is true
if (condition) {
//code to be executed if condition is true
}
}
Nested IF Statement Example
IF…ELSE Statement
▪ Executed whether condition is true or false.
▪ Executes one block of code if the specified condition
is true and another block of code if the condition is
false.
▪ Syntax:
IF…ELSE Statement Example
IF…ELSEIF…ELSE Statement
▪ Executes different codes for more than two
conditions.
▪ Syntax:
IF…ELSEIF…ELSE Statement
Example
SWITCH Statement
▪ Used to perform different actions based on different
conditions.
▪ Selects one of many blocks of code to be executed.
▪ Syntax:
SWITCH Statement Example
ITERATIVE STATEMENTS IN PHP
Computer Science
Iterative Statement (Loops)
Computer Science
Functions in PHP
▪ When a function is
completed/executed, all of its
variables are deleted.
▪ Use static keyword for a local
variable not to be deleted.
Superglobals
Computer Science
Array in PHP
▪ A special variable which can hold more than one
value at a time.
▪ Stores multiple values in one single variable.
▪ array() function is used to create an array.
○ Indexed array: array with a numeric index
○ Associative array: array with named keys
○ Multidimensional array: array within an array
Length of Array in PHP
▪ count() function is used to return the length
(number of elements) of an array.
EXECUTE PHP WITH
XAMPP/WAMP
Computer Science
Execute PHP with XAMPP
▪ Requirements:
○ XAMPP, Notepad++, Browser
▪ Run the Apache and Mysql Services from XAMPP.
▪ Write your php script in Notepad++.
▪ Save your file inside the “htdocs” folder inside the
Xampp folder location.
▪ From your browser, use url according to your xampp
folder structure. Ex: localhost/folder/file.php
Execute PHP with WAMP
▪ Requirements:
○ WAMP, Notepad++, Browser
▪ Run the Apache and Mysql Services from WAMP.
▪ Write your php script in Notepad++.
▪ Save your file inside the “www” folder inside the
wamp folder location.
▪ From your browser, use url according to your wamp
folder structure. Ex: localhost/folder/file.php
FORM HANDLING
Computer Science
HTML Form
Computer Science
Database and PHP
Computer Science
Create a Database using
MySQLi
▪ Connection to database server is made.
▪ CREATE DATABASE statement is used to create
database in MySQL.
▪ Execute SQL query by passing it to the PHP
mysqli_query() function. Returns false if failed.
Create a Database using MySQLi
Create a Database using MySQLi
Create a Table using MySQLi
Computer Science
Require and Include in PHP
Computer Science
Preface to JavaScript
▪ Self Study
○ IF
○ IF ELSE
○ IF ELSE IF
○ SWITCH
JavaScript Loops
▪ Self Study
○ FOR
○ WHILE
○ DO-WHILE
○ NESTED FOR
JavaScript Input
Computer Science