SlideShare a Scribd company logo
PHP

BY :Mohammed Mushtaq Ahmed
Contents
•
•
•
•
•

HTML
JavaScript
PHP
MySQL
WAMP
HTML
•
•
•
•

Hyper Text Markup Language
Developed by Tim Berners lee in 1990.
Easy to use ,Easy to learn
Markup tags tell the browser how to display
the page.
• A HTML file must have an extension .htm
or.html.
Cont…..
• HTML tags are surrounded by “<“ and “>”
(angular brackets).
• Tags normally come in pairs like <H1> and
</H1>.
• Tags are not case sensitive i.e. <p> is same
as <P>.
• The first tag in a pair is the start tag, the
second tag is the end tag and so on ……,.
Cont…
JavaScript
•
•
•
•

JavaScript ≠ Java
Developed by Netscape
Purpose: to Create Dynamic websites
Starts with < script type=“text/java script”>
and ends with < /script>.
• Easy to learn , easy to use.
• More powerful,loosely typed
Cont…
•
•
•
•
•

Conversion automatically
Used to customize web pages.
Make pages more dynamic.
To validate CGI forms.
It’s limited (can not develpe standalone
aplli.)
• Widely Used
About PHP
•
•
•
•
•

PHP (Hypertext Preprocessor),
Dynamic web pages.
It’s like ASP.
PHP scripts are executed on the server .
PHP files have a file extension of ".php",
".php3", or ".phtml".
Why PHP
• PHP runs on different platforms (Windows,
Linux, Unix, etc.)
• PHP is compatible with almost all servers
used today (Apache, IIS, etc.)
• PHP is FREE to download from the official
PHP resource: www.php.net
• PHP is easy to learn and runs efficiently on
the server side
Cont…
• A PHP scripting block always starts with
<?php and ends with ?>.
• Can be placed any where within a
document.
• We can start a scripting block with <? and
end with ?> on servers that provide
shorthand support.
• It is advised to use standard tags for best
outputs.
Features of PHP…
• Speed
• Full database Support
• Open source and free to download and
use.
• Cross platform
• Easy for newcomer and advance features
Cont…
• Used to create dynamic web pages.
• Freedom to choose any operating system and a web
server.
• Not constrained to output only HTML. PHP's abilities
include outputting images, PDF files etc.
• Support for a wide range of databases. Eg: dBase,
MySQL, Oracle etc.
Working of PHP…

• URL is typed in the browser.
• The browser sends a request to the web server.
• The web server then calls the PHP script on that
page.
• The PHP module executes the script, which then
sends out the result in the form of HTML back to
the browser, which can be seen on the screen.
PHP BASICS…
A PHP scripting block always starts with <?php
and ends with ?>
A PHP scripting block can be placed anywhere
in the document.
On servers with shorthand support enabled you can
start a scripting block with <? and end with ?>
For maximum compatibility;
use the standard form <?php ?>rather than the
shorthand form <? ?>
Structure of PHP Programe
<html>
<body>
<?php
echo “hi friends…..";
?>
</body>
</html>
Combining PHP with HTml
<html>
<head>
<title>My First Web Page</title>
</head>
<body bgcolor="white">
<p>A Paragraph of Text</p>
<?php
Echo ”HELLO”;
?>
</body>
</html>
Comments in PHP
• In PHP, we use // to make a single-line
comment or /* and */ to make a large
comment block.
Example :
<?php
//This is a comment
/* This is a comment block */
?>

17
PHP Variables
• A variable is used to store information.
– text strings
– numbers
– Arrays

• Examples:

– A variable containing a string:
<?php
$txt="Hello World!";
?>

– A variable containing a number:
<?php
$x=16;
?>
18
Naming Rules for Variables
• Must start with a letter or an underscore "_"
• Can only contain alpha-numeric characters
and underscores (a-z, A-Z, 0-9, and _ )
• Should not contain spaces. If a variable name
is more than one word, it should be
separated with an underscore ($my_string),
or with capitalization ($myString)
19
PHP String Variables
• It is used to store and manipulate text.
• Example:
<?php
$txt1="Hello World!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?>

• Output:
Hello World! What a nice day!
20
The strlen() function
• The strlen() function is used to return the
length of a string.
• Example:
<?php
echo strlen("Hello world!");
?>

• Output:
12

21
Assignment Operators

22
Comparison Operators

23
Logical Operators

24
Conditional Statements

25
PHP If...Else Statements
Conditional statements are used to perform
different actions based on different conditions.
– if statement - use this statement to execute some code only if
a specified condition is true
– if...else statement - use this statement to execute some code
if a condition is true and another code if the condition is false
– if...elseif....else statement - use this statement to select one
of several blocks of code to be executed
– switch statement - use this statement to select one of many
blocks of code to be executed
26
Example: if..else statement
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
</body>
</html>
27
Continue.. If..else
• If more than one line should be executed if a condition is
true/false, the lines should be enclosed within curly braces:
• Example:
<?php
$d=date("D");
if ($d=="Fri")
{
echo "Hello!<br />";
echo "Have a nice weekend!";
echo "See you on Monday!";
}
?>

28
PHP Switch Statement
Conditional statements are used to perform different actions
based on different conditions.
Example:
<?php
switch ($x) {
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>

29
PHP (Advanced Topics)
Arrays, Loops, Functions, Forms,
Database Handling

30
Arrays

31
Arrays
There are three different kind of arrays:
• Numeric array - An array with a numeric ID key
• Associative array - An array where each ID key is
associated with a value
• Multidimensional array - An array containing one or
more arrays

32
Numeric Array
Example 1
In this example the ID key (index) is
automatically assigned:
$names = array("Peter", "Quagmire", "Joe");

33
Numeric Array
Example 2
In this example we assign the ID key manually:
$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";

34
Displaying Numeric Array
<?php
$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";
echo $names[1] . " and " . $names[2] .
" are ". $names[0] . "'s neighbors";
?>
Output
Quagmire and Joe are Peter's neighbors
35
Associative Array
Example 1
$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);

Example 2
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";

Displaying Associative Array
<?php
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";
echo "Peter is " . $ages['Peter'] . " years old.";
?>

Output

Peter is 32 years old.
36
Loops

37
Loops
In PHP we have the following looping statements:
• while - loops through a block of code if and as long as a
specified condition is true
• do...while - loops through a block of code once, and then
repeats the loop as long as a special condition is true
• for - loops through a block of code a specified number of
times
• foreach - loops through a block of code for each element in
an array
38
while & do while Loops
//Programs Displaying value from 1 to 5.
<html>
<body>
<?php
$i=1;
while($i<=5)
{
echo "The number is " . $i . "<br />";
$i++;
}
?>
</body>
</html>

<html>
<body>
<?php
$i=0;
do
{
$i++;
echo "The number is " . $i . "<br />";
}
while ($i<5);
?>
</body>
</html>
39
for and foreach Loops
//The following examples prints the text "Hello World!" five times:

<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
{
echo "Hello World!<br />";
}
?>
</body>
</html>

<html>
<body>
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
}
?>
</body>
</html>
40
Functions

41
Functions
Creating PHP functions:
• All functions start with the word "function()“
• The name can start with a letter or underscore (not a
number)
• Add a "{" – The code starts after the opening curly brace
• Insert the code or STATEMENTS
• Add a "}" - The code is finished by a closing curly brace

42
Functions
//A simple function that writes name when
it is called:
<html>
<body>
<?php
function writeMyName()
{
echo "Kai Jim Refsnes";
}
writeMyName();
?>
</body>
Output
</html>

Hello world!
My name is Kai Jim Refsnes.
That's right, Kai Jim Refsnes is my name.

// Now we will use the
function in a PHP script:

<html><body>
<?php
function writeMyName()
{
echo "Kai Jim Refsnes";
}
echo "Hello world!<br />";
echo "My name is ";
writeMyName();
echo ".<br />That's right, ";
writeMyName();
echo " is my name.";
?>
</body> </html>

43
Functions with Parameters
//The following example will write different first names, but the same last name:

<html><body>
<?php
function writeMyName($fname)
{
echo $fname . " Refsnes.<br />";
}
echo "My name is ";
writeMyName("Kai Jim");
echo "My name is ";
writeMyName("Hege");
echo "My name is ";
writeMyName("Stale");
?>
</body></html>

//The following function has two
parameters: <html><body>
<?php
function writeMyName($fname,
$punctuation)
{
echo $fname . " Refsnes" . $punctuation .
“<br/>";
}
echo "My name is ";
writeMyName("Kai Jim",".");
echo "My name is ";
Output
writeMyName("Hege","!"); name is Kai Jim Refsnes.
My
My name is Hege Refsnes.
echo "My name is ";
My name is Stale Refsnes.
44
writeMyName("Ståle","...");
Functions: Return Values
//Functions can also be used to return values.
<html>
<body>
<?php
function add($x,$y)
{
Output
$total = $x + $y;
1 + 16 =
return $total;
}
echo "1 + 16 = " . add(1,16);
?>
</body>
</html>

17

45
Form (User Input)

46
PHP Form
The PHP $_GET and $_POST variables are used to
retrieve information from forms, like user input.
PHP Form Handling
The most important thing to notice when dealing
with HTML forms and PHP is that any form element
in an HTML page will automatically be available to
your PHP scripts.

47
PHP Forms ($_POST)
Example

1

//The file name is input.html
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
// The "welcome.php" file looks like this:
</form>
<html> <body>
</body>
Welcome <?php echo $_POST["name"]; ?
</html>

2

>.<br />
You are <?php echo $_POST["age"]; ?>
The example HTML page above contains two input fields and a submit button. When the
years old.
user fills in this form and click on the submit button, the form data is sent to the
"welcome.php" file.
</body> </html>
3

Output

Welcome John.
48
You are 28 years
$_POST, $_GET, and $_REQUEST
• The $_POST variable is an array of variable names
and values sent by the HTTP POST method.
• When using the $_GET variable all variable names
and values are displayed in the URL. So this method
should not be used to send sensitive information.
• The PHP $_REQUEST variable can be used to get the
result from form data sent with both the GET and
POST methods.

49
$_POST, $_GET, and $_REQUEST
//FILE calling welcome.php
<form action="welcome.php" method="get">
Name: <input type="text" name="name" />
$_GET Example:
//PHP file can now use the $_GET variable to catch the form data
Welcome <?php echo $_GET["name"]; ?>.<br />

OR

$_REQUEST Example:
//PHP file can now use the $_GET variable to catch the form data
Welcome <?php echo $_REQUEST["name"]; ?>.<br />

File 2: PHP

File 1: HTML

Example:

50
Database Handling
PHP and MySQL

51
MySQL
• MySQL is a database.
• The data in MySQL is stored in database
objects called tables.
• The data in MySQL is stored in database
objects called tables.
• A database most often contains one or more
tables. Each table is identified by a name (e.g.
"Customers" or "Orders").
52
MySQL
All SQL queries are applicable in MySQL e.g. SELECT,
CREATE, INSERT, UPDATE, and DELETE.
Below is an example of a table called "Persons":
LastName

FirstName

Address

City

Hansen

Ola

Timoteivn 10

Sandnes

Svendson

Tove

Borgvn 23

Sandnes

Pettersen

Kari

Storgt 20

Stavanger

53
PHP MySQL Connection
Syntax
mysql_connect(servername,username,password);
Parameter Description
servername (Optional) - Specifies the server to connect to.
Default value is "localhost:3306"
username (Optional) - Specifies the username to log in with.
Default value is the name of the user
that owns the server process
password (Optional) - Specifies the password to log in with.
Default is "".
54
Opening PHP MySQL Connection
Example
In the following example we store the connection in a variable
($con) for later use in the script. The "die" part will be executed
if the connection fails:
<?php
$con = mysql_connect("localhost",“user",“password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
55
Closing PHP MySQL Connection
The connection will be closed automatically when the script ends.
To close the connection before, use the mysql_close() function:
<?php
$con = mysql_connect("localhost",“user",“password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code

mysql_close($con);
?>

56
Create Database
Syntax
CREATE DATABASE database_name
Example
The following example creates a database called "my_db":
<?php
$con =
mysql_connect("localhost“,
”user_name",“password");
if (!$con)
{

die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{ echo "Database created"; }
else
{ echo "Error creating database: " . mysql_error(); }
mysql_close($con);
?>
57
Create Table
Syntax

Example:

CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)

<?php
$con =
mysql_connect("localhost",
“user",“password");
if (!$con)
{ die('Could not connect: ' .
mysql_error()); }
// Create database
if (mysql_query("CREATE DATABASE
my_db",$con))
{ echo "Database created"; }
else
{ echo "Error creating database: " .
mysql_error(); }

FirstName
varchar(15),
LastName
varchar(15),
Age int )";
// Execute query
mysql_query($sql,

58
Create Table
Primary Key and Auto Increment Fields
• Each table should have a primary key field.
• The primary key field cannot be null & requires a value.
Example

$sql = "CREATE TABLE Persons

(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int
)";
mysql_query($sql,$con);
59
Insert Data
Syntax:
INSERT INTO table_name
VALUES (value1, value2, value3,...)
OR
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

60
Insert Data
Example
<?php
$con = mysql_connect("localhost", “user_name",“password");
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");
mysql_close($con);
?>
61
Insert Data (HTML FORM to DB)
<!-- Save this file as web_form.html -->
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
Note: Two files are required to input
Note: Two files are required to input
and store data. First, web_form.html
</form>
and store data. First, web_form.html
file containing HTML web form.
file containing HTML web form.
</body>
Secondly, insert.php (on next slide) file
Secondly, insert.php (on next slide) file
</html>
to store received data into database.
to store received data into database.
62
Insert Data (HTML FORM to DB)
//Save this file as insert.php
<?php
$con = mysql_connect("localhost", “user_name",“password");
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{ die('Error: ' . mysql_error()); }
echo "1 record added";
mysql_close($con)
?>
63
Retrieve Data
Example:

mysql_query() function is used to send
a query.

<?php
$con = mysql_connect("localhost", “user_name",“password");
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))
{ echo $row['FirstName'] . " " . $row['LastName']; echo "<br />“;}
mysql_close($con);
?>
64
Display Retrieved Data
Example:

<th>Lastname</th>
</tr>";
<?php
while($row =
$con = mysql_connect("localhost",
mysql_fetch_array($result))
“user_name",“password");
if (!$con)
{
{
echo "<tr>";
die('Could not connect: ' . mysql_error());
echo "<td>" . $row['FirstName'] .
}
"</td>";
mysql_select_db("my_db", $con);
echo "<td>" . $row['LastName'] .
$result = mysql_query("SELECT * FROM Persons");
"</td>";
echo "<table border='1'>
echo "</tr>";
<tr>
<th>Firstname</th>
}
echo "</table>";
65
Searching (using WHERE clause)
Example:
<?php
$con = mysql_connect("localhost",“user_name",“password");
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");
while($row = mysql_fetch_array($result))
{ echo $row['FirstName'] . " " . $row['LastName'];
Output
echo "<br />"; }
Peter Griffin
?>
66
Update
Example
<?php
$con = mysql_connect("localhost",“user_name",”password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("UPDATE Persons SET Age = '36'
WHERE FirstName = 'Peter' AND LastName = 'Griffin'");
mysql_close($con);
?>
Peter Griffin’s age was 35

Now age changed into 36
67
Delete
Example:
<?php
$con = mysql_connect("localhost",“user_name",“password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("DELETE FROM Persons WHERE LastName='Griffin'");
mysql_close($con);
?>

68
WAMP Server
(Apache, PHP, and
MySQL)
Installation
69
Installation
What do you need?
Most people would prefer to install all-in-one
solution:
– WampServer -> for Windows platform Includes:
• Apache 2.2.11 - MySQL 5.1.36 - PHP 5.3.0
• Download from http://www.wampserver.com/en/

– http://lamphowto.com/ -> for Linux platform
70
Software to be used
Wampserver (Apache, MySQL, PHP for Windows)
WampServer provides a plateform to
develop web applications using PHP,
MySQL and Apache web server. After
successful installation, you should
have an new icon in the bottom right,
where the clock is:

71
WAMP
Local Host
IP address 127.0.0.1

72
Saving your PHP files
Whenever you create a new PHP page,
you need to save it in your WWW
directory. You can see where this is by
clicking its item on the menu:
When you click on www directory You'll
probably have only two files, index and
testmysql.
This www folder for Wampserver is usally at this location on your hard drive:
c:/wamp/www/
73
Thank You.

More Related Content

What's hot

PHP.ppt
PHP.pptPHP.ppt
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Php tutorial
Php  tutorialPhp  tutorial
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
dharmendra kumar dhakar
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
abhilashagupta
 
HTML/CSS Crash Course (april 4 2017)
HTML/CSS Crash Course (april 4 2017)HTML/CSS Crash Course (april 4 2017)
HTML/CSS Crash Course (april 4 2017)
Daniel Friedman
 
JavaScript Lecture notes.pptx
JavaScript Lecture notes.pptxJavaScript Lecture notes.pptx
JavaScript Lecture notes.pptx
NishaRohit6
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
Santhiya Grace
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 

What's hot (20)

PHP.ppt
PHP.pptPHP.ppt
PHP.ppt
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Php ppt
Php pptPhp ppt
Php ppt
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php
PhpPhp
Php
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
 
HTML/CSS Crash Course (april 4 2017)
HTML/CSS Crash Course (april 4 2017)HTML/CSS Crash Course (april 4 2017)
HTML/CSS Crash Course (april 4 2017)
 
JavaScript Lecture notes.pptx
JavaScript Lecture notes.pptxJavaScript Lecture notes.pptx
JavaScript Lecture notes.pptx
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Lesson 5 php operators
Lesson 5   php operatorsLesson 5   php operators
Lesson 5 php operators
 
Java script
Java scriptJava script
Java script
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Php basics
Php basicsPhp basics
Php basics
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 

Viewers also liked

Curso Php y Mysql desde cero de Developero
Curso Php y Mysql desde cero de DeveloperoCurso Php y Mysql desde cero de Developero
Curso Php y Mysql desde cero de Developero
⚛️ Juan Correa
 
Associative arrays in PHP
Associative arrays in PHPAssociative arrays in PHP
Associative arrays in PHP
Suraj Motee
 
Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)
Anil Kumar
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
Pharmacy inventory
Pharmacy inventoryPharmacy inventory
Pharmacy inventory
devnetit
 
Buku Ajar Pemrograman Web
Buku Ajar Pemrograman WebBuku Ajar Pemrograman Web
Buku Ajar Pemrograman Web
Muhammad Junaini
 
"Pharmacy system"
"Pharmacy system""Pharmacy system"
"Pharmacy system"vivek kct
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
Ahmed Swilam
 
Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document
Habitamu Asimare
 
Medical Store Management System Software Engineering Project
Medical Store Management System Software Engineering ProjectMedical Store Management System Software Engineering Project
Medical Store Management System Software Engineering Projecthani2253
 
Inventory management system
Inventory management systemInventory management system
Inventory management systemcopo7475
 
Data Flow Diagram Example
Data Flow Diagram ExampleData Flow Diagram Example
Data Flow Diagram ExampleKaviarasu D
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
Shawn Calvert
 

Viewers also liked (14)

Curso Php y Mysql desde cero de Developero
Curso Php y Mysql desde cero de DeveloperoCurso Php y Mysql desde cero de Developero
Curso Php y Mysql desde cero de Developero
 
Associative arrays in PHP
Associative arrays in PHPAssociative arrays in PHP
Associative arrays in PHP
 
Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)Music Downloading Website (HTML,CSS,PHP Presentation)
Music Downloading Website (HTML,CSS,PHP Presentation)
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Pharmacy inventory
Pharmacy inventoryPharmacy inventory
Pharmacy inventory
 
Buku Ajar Pemrograman Web
Buku Ajar Pemrograman WebBuku Ajar Pemrograman Web
Buku Ajar Pemrograman Web
 
"Pharmacy system"
"Pharmacy system""Pharmacy system"
"Pharmacy system"
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document Pharmacy management system Requirement Analysis and Elicitation Document
Pharmacy management system Requirement Analysis and Elicitation Document
 
Medical Store Management System Software Engineering Project
Medical Store Management System Software Engineering ProjectMedical Store Management System Software Engineering Project
Medical Store Management System Software Engineering Project
 
Inventory management system
Inventory management systemInventory management system
Inventory management system
 
Data Flow Diagram Example
Data Flow Diagram ExampleData Flow Diagram Example
Data Flow Diagram Example
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 

Similar to PHP complete reference with database concepts for beginners

Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
Php(report)
Php(report)Php(report)
Php(report)Yhannah
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
php 1
php 1php 1
php 1
tumetr1
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 
Php Tutorial
Php TutorialPhp Tutorial
Day1
Day1Day1
Day1
IRWAA LLC
 
Intro to php
Intro to phpIntro to php
Intro to php
Ahmed Farag
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
Annujj Agrawaal
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
Brainware Consultancy Pvt Ltd
 
Php
PhpPhp
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
Niladri Karmakar
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
Elmer Concepcion Jr.
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
vibrantuser
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 

Similar to PHP complete reference with database concepts for beginners (20)

Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
Php(report)
Php(report)Php(report)
Php(report)
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
php 1
php 1php 1
php 1
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Day1
Day1Day1
Day1
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
Intro to php
Intro to phpIntro to php
Intro to php
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Php
PhpPhp
Php
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 

Recently uploaded

135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering
Manu Mitra
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
HeidiLivengood
 
salivary gland disorders.pdf nothing more
salivary gland disorders.pdf nothing moresalivary gland disorders.pdf nothing more
salivary gland disorders.pdf nothing more
GokulnathMbbs
 
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring ChapterHow Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
Hector Del Castillo, CPM, CPMM
 
Full Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptxFull Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptx
mmorales2173
 
15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf
15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf
15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf
gobogo3542
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!
LukeRoyak
 
Brand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio IBrand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio I
thomasaolson2000
 
Andrea Kate Portfolio Presentation.pdf
Andrea Kate  Portfolio  Presentation.pdfAndrea Kate  Portfolio  Presentation.pdf
Andrea Kate Portfolio Presentation.pdf
andreakaterasco
 
New Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdfNew Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdf
Dr. Mary Askew
 
My Story of Getting into Tech By Gertrude Chilufya Westrin
My Story of Getting into Tech By Gertrude Chilufya WestrinMy Story of Getting into Tech By Gertrude Chilufya Westrin
My Story of Getting into Tech By Gertrude Chilufya Westrin
AlinaseFaith
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
foismail170
 
DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
FarzanaRbcomcs
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
taexnic
 
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdfDOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
Pushpendra Kumar
 
133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research
Manu Mitra
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
larisashrestha558
 
132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences
Manu Mitra
 
How to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and BusinessHow to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and Business
ideatoipo
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
foismail170
 

Recently uploaded (20)

135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
 
salivary gland disorders.pdf nothing more
salivary gland disorders.pdf nothing moresalivary gland disorders.pdf nothing more
salivary gland disorders.pdf nothing more
 
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring ChapterHow Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
How Mentoring Elevates Your PM Career | PMI Silver Spring Chapter
 
Full Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptxFull Sail_Morales_Michael_SMM_2024-05.pptx
Full Sail_Morales_Michael_SMM_2024-05.pptx
 
15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf
15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf
15385-LESSON PLAN- 7TH - SS-Insian Constitution an Introduction.pdf
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!
 
Brand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio IBrand Identity For A Sportscaster Project and Portfolio I
Brand Identity For A Sportscaster Project and Portfolio I
 
Andrea Kate Portfolio Presentation.pdf
Andrea Kate  Portfolio  Presentation.pdfAndrea Kate  Portfolio  Presentation.pdf
Andrea Kate Portfolio Presentation.pdf
 
New Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdfNew Explore Careers and College Majors 2024.pdf
New Explore Careers and College Majors 2024.pdf
 
My Story of Getting into Tech By Gertrude Chilufya Westrin
My Story of Getting into Tech By Gertrude Chilufya WestrinMy Story of Getting into Tech By Gertrude Chilufya Westrin
My Story of Getting into Tech By Gertrude Chilufya Westrin
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
 
DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
 
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdfDOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
DOC-20240602-WA0001..pdf DOC-20240602-WA0001..pdf
 
133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
 
132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences
 
How to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and BusinessHow to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and Business
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
 

PHP complete reference with database concepts for beginners

  • 3. HTML • • • • Hyper Text Markup Language Developed by Tim Berners lee in 1990. Easy to use ,Easy to learn Markup tags tell the browser how to display the page. • A HTML file must have an extension .htm or.html.
  • 4. Cont….. • HTML tags are surrounded by “<“ and “>” (angular brackets). • Tags normally come in pairs like <H1> and </H1>. • Tags are not case sensitive i.e. <p> is same as <P>. • The first tag in a pair is the start tag, the second tag is the end tag and so on ……,.
  • 6. JavaScript • • • • JavaScript ≠ Java Developed by Netscape Purpose: to Create Dynamic websites Starts with < script type=“text/java script”> and ends with < /script>. • Easy to learn , easy to use. • More powerful,loosely typed
  • 7. Cont… • • • • • Conversion automatically Used to customize web pages. Make pages more dynamic. To validate CGI forms. It’s limited (can not develpe standalone aplli.) • Widely Used
  • 8. About PHP • • • • • PHP (Hypertext Preprocessor), Dynamic web pages. It’s like ASP. PHP scripts are executed on the server . PHP files have a file extension of ".php", ".php3", or ".phtml".
  • 9. Why PHP • PHP runs on different platforms (Windows, Linux, Unix, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP is FREE to download from the official PHP resource: www.php.net • PHP is easy to learn and runs efficiently on the server side
  • 10. Cont… • A PHP scripting block always starts with <?php and ends with ?>. • Can be placed any where within a document. • We can start a scripting block with <? and end with ?> on servers that provide shorthand support. • It is advised to use standard tags for best outputs.
  • 11. Features of PHP… • Speed • Full database Support • Open source and free to download and use. • Cross platform • Easy for newcomer and advance features
  • 12. Cont… • Used to create dynamic web pages. • Freedom to choose any operating system and a web server. • Not constrained to output only HTML. PHP's abilities include outputting images, PDF files etc. • Support for a wide range of databases. Eg: dBase, MySQL, Oracle etc.
  • 13. Working of PHP… • URL is typed in the browser. • The browser sends a request to the web server. • The web server then calls the PHP script on that page. • The PHP module executes the script, which then sends out the result in the form of HTML back to the browser, which can be seen on the screen.
  • 14. PHP BASICS… A PHP scripting block always starts with <?php and ends with ?> A PHP scripting block can be placed anywhere in the document. On servers with shorthand support enabled you can start a scripting block with <? and end with ?> For maximum compatibility; use the standard form <?php ?>rather than the shorthand form <? ?>
  • 15. Structure of PHP Programe <html> <body> <?php echo “hi friends….."; ?> </body> </html>
  • 16. Combining PHP with HTml <html> <head> <title>My First Web Page</title> </head> <body bgcolor="white"> <p>A Paragraph of Text</p> <?php Echo ”HELLO”; ?> </body> </html>
  • 17. Comments in PHP • In PHP, we use // to make a single-line comment or /* and */ to make a large comment block. Example : <?php //This is a comment /* This is a comment block */ ?> 17
  • 18. PHP Variables • A variable is used to store information. – text strings – numbers – Arrays • Examples: – A variable containing a string: <?php $txt="Hello World!"; ?> – A variable containing a number: <?php $x=16; ?> 18
  • 19. Naming Rules for Variables • Must start with a letter or an underscore "_" • Can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ) • Should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString) 19
  • 20. PHP String Variables • It is used to store and manipulate text. • Example: <?php $txt1="Hello World!"; $txt2="What a nice day!"; echo $txt1 . " " . $txt2; ?> • Output: Hello World! What a nice day! 20
  • 21. The strlen() function • The strlen() function is used to return the length of a string. • Example: <?php echo strlen("Hello world!"); ?> • Output: 12 21
  • 26. PHP If...Else Statements Conditional statements are used to perform different actions based on different conditions. – if statement - use this statement to execute some code only if a specified condition is true – if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false – if...elseif....else statement - use this statement to select one of several blocks of code to be executed – switch statement - use this statement to select one of many blocks of code to be executed 26
  • 27. Example: if..else statement <html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; ?> </body> </html> 27
  • 28. Continue.. If..else • If more than one line should be executed if a condition is true/false, the lines should be enclosed within curly braces: • Example: <?php $d=date("D"); if ($d=="Fri") { echo "Hello!<br />"; echo "Have a nice weekend!"; echo "See you on Monday!"; } ?> 28
  • 29. PHP Switch Statement Conditional statements are used to perform different actions based on different conditions. Example: <?php switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; } ?> 29
  • 30. PHP (Advanced Topics) Arrays, Loops, Functions, Forms, Database Handling 30
  • 32. Arrays There are three different kind of arrays: • Numeric array - An array with a numeric ID key • Associative array - An array where each ID key is associated with a value • Multidimensional array - An array containing one or more arrays 32
  • 33. Numeric Array Example 1 In this example the ID key (index) is automatically assigned: $names = array("Peter", "Quagmire", "Joe"); 33
  • 34. Numeric Array Example 2 In this example we assign the ID key manually: $names[0] = "Peter"; $names[1] = "Quagmire"; $names[2] = "Joe"; 34
  • 35. Displaying Numeric Array <?php $names[0] = "Peter"; $names[1] = "Quagmire"; $names[2] = "Joe"; echo $names[1] . " and " . $names[2] . " are ". $names[0] . "'s neighbors"; ?> Output Quagmire and Joe are Peter's neighbors 35
  • 36. Associative Array Example 1 $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Example 2 $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; Displaying Associative Array <?php $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; echo "Peter is " . $ages['Peter'] . " years old."; ?> Output Peter is 32 years old. 36
  • 38. Loops In PHP we have the following looping statements: • while - loops through a block of code if and as long as a specified condition is true • do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true • for - loops through a block of code a specified number of times • foreach - loops through a block of code for each element in an array 38
  • 39. while & do while Loops //Programs Displaying value from 1 to 5. <html> <body> <?php $i=1; while($i<=5) { echo "The number is " . $i . "<br />"; $i++; } ?> </body> </html> <html> <body> <?php $i=0; do { $i++; echo "The number is " . $i . "<br />"; } while ($i<5); ?> </body> </html> 39
  • 40. for and foreach Loops //The following examples prints the text "Hello World!" five times: <html> <body> <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> </body> </html> <html> <body> <?php $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: " . $value . "<br />"; } ?> </body> </html> 40
  • 42. Functions Creating PHP functions: • All functions start with the word "function()“ • The name can start with a letter or underscore (not a number) • Add a "{" – The code starts after the opening curly brace • Insert the code or STATEMENTS • Add a "}" - The code is finished by a closing curly brace 42
  • 43. Functions //A simple function that writes name when it is called: <html> <body> <?php function writeMyName() { echo "Kai Jim Refsnes"; } writeMyName(); ?> </body> Output </html> Hello world! My name is Kai Jim Refsnes. That's right, Kai Jim Refsnes is my name. // Now we will use the function in a PHP script: <html><body> <?php function writeMyName() { echo "Kai Jim Refsnes"; } echo "Hello world!<br />"; echo "My name is "; writeMyName(); echo ".<br />That's right, "; writeMyName(); echo " is my name."; ?> </body> </html> 43
  • 44. Functions with Parameters //The following example will write different first names, but the same last name: <html><body> <?php function writeMyName($fname) { echo $fname . " Refsnes.<br />"; } echo "My name is "; writeMyName("Kai Jim"); echo "My name is "; writeMyName("Hege"); echo "My name is "; writeMyName("Stale"); ?> </body></html> //The following function has two parameters: <html><body> <?php function writeMyName($fname, $punctuation) { echo $fname . " Refsnes" . $punctuation . “<br/>"; } echo "My name is "; writeMyName("Kai Jim","."); echo "My name is "; Output writeMyName("Hege","!"); name is Kai Jim Refsnes. My My name is Hege Refsnes. echo "My name is "; My name is Stale Refsnes. 44 writeMyName("Ståle","...");
  • 45. Functions: Return Values //Functions can also be used to return values. <html> <body> <?php function add($x,$y) { Output $total = $x + $y; 1 + 16 = return $total; } echo "1 + 16 = " . add(1,16); ?> </body> </html> 17 45
  • 47. PHP Form The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. PHP Form Handling The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. 47
  • 48. PHP Forms ($_POST) Example 1 //The file name is input.html <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> // The "welcome.php" file looks like this: </form> <html> <body> </body> Welcome <?php echo $_POST["name"]; ? </html> 2 >.<br /> You are <?php echo $_POST["age"]; ?> The example HTML page above contains two input fields and a submit button. When the years old. user fills in this form and click on the submit button, the form data is sent to the "welcome.php" file. </body> </html> 3 Output Welcome John. 48 You are 28 years
  • 49. $_POST, $_GET, and $_REQUEST • The $_POST variable is an array of variable names and values sent by the HTTP POST method. • When using the $_GET variable all variable names and values are displayed in the URL. So this method should not be used to send sensitive information. • The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods. 49
  • 50. $_POST, $_GET, and $_REQUEST //FILE calling welcome.php <form action="welcome.php" method="get"> Name: <input type="text" name="name" /> $_GET Example: //PHP file can now use the $_GET variable to catch the form data Welcome <?php echo $_GET["name"]; ?>.<br /> OR $_REQUEST Example: //PHP file can now use the $_GET variable to catch the form data Welcome <?php echo $_REQUEST["name"]; ?>.<br /> File 2: PHP File 1: HTML Example: 50
  • 52. MySQL • MySQL is a database. • The data in MySQL is stored in database objects called tables. • The data in MySQL is stored in database objects called tables. • A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). 52
  • 53. MySQL All SQL queries are applicable in MySQL e.g. SELECT, CREATE, INSERT, UPDATE, and DELETE. Below is an example of a table called "Persons": LastName FirstName Address City Hansen Ola Timoteivn 10 Sandnes Svendson Tove Borgvn 23 Sandnes Pettersen Kari Storgt 20 Stavanger 53
  • 54. PHP MySQL Connection Syntax mysql_connect(servername,username,password); Parameter Description servername (Optional) - Specifies the server to connect to. Default value is "localhost:3306" username (Optional) - Specifies the username to log in with. Default value is the name of the user that owns the server process password (Optional) - Specifies the password to log in with. Default is "". 54
  • 55. Opening PHP MySQL Connection Example In the following example we store the connection in a variable ($con) for later use in the script. The "die" part will be executed if the connection fails: <?php $con = mysql_connect("localhost",“user",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code ?> 55
  • 56. Closing PHP MySQL Connection The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function: <?php $con = mysql_connect("localhost",“user",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code mysql_close($con); ?> 56
  • 57. Create Database Syntax CREATE DATABASE database_name Example The following example creates a database called "my_db": <?php $con = mysql_connect("localhost“, ”user_name",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (mysql_query("CREATE DATABASE my_db",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } mysql_close($con); ?> 57
  • 58. Create Table Syntax Example: CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... ) <?php $con = mysql_connect("localhost", “user",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } // Create database if (mysql_query("CREATE DATABASE my_db",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } FirstName varchar(15), LastName varchar(15), Age int )"; // Execute query mysql_query($sql, 58
  • 59. Create Table Primary Key and Auto Increment Fields • Each table should have a primary key field. • The primary key field cannot be null & requires a value. Example $sql = "CREATE TABLE Persons ( personID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(personID), FirstName varchar(15), LastName varchar(15), Age int )"; mysql_query($sql,$con); 59
  • 60. Insert Data Syntax: INSERT INTO table_name VALUES (value1, value2, value3,...) OR INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) 60
  • 61. Insert Data Example <?php $con = mysql_connect("localhost", “user_name",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire', '33')"); mysql_close($con); ?> 61
  • 62. Insert Data (HTML FORM to DB) <!-- Save this file as web_form.html --> <html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> Note: Two files are required to input Note: Two files are required to input and store data. First, web_form.html </form> and store data. First, web_form.html file containing HTML web form. file containing HTML web form. </body> Secondly, insert.php (on next slide) file Secondly, insert.php (on next slide) file </html> to store received data into database. to store received data into database. 62
  • 63. Insert Data (HTML FORM to DB) //Save this file as insert.php <?php $con = mysql_connect("localhost", “user_name",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> 63
  • 64. Retrieve Data Example: mysql_query() function is used to send a query. <?php $con = mysql_connect("localhost", “user_name",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />“;} mysql_close($con); ?> 64
  • 65. Display Retrieved Data Example: <th>Lastname</th> </tr>"; <?php while($row = $con = mysql_connect("localhost", mysql_fetch_array($result)) “user_name",“password"); if (!$con) { { echo "<tr>"; die('Could not connect: ' . mysql_error()); echo "<td>" . $row['FirstName'] . } "</td>"; mysql_select_db("my_db", $con); echo "<td>" . $row['LastName'] . $result = mysql_query("SELECT * FROM Persons"); "</td>"; echo "<table border='1'> echo "</tr>"; <tr> <th>Firstname</th> } echo "</table>"; 65
  • 66. Searching (using WHERE clause) Example: <?php $con = mysql_connect("localhost",“user_name",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons WHERE FirstName='Peter'"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; Output echo "<br />"; } Peter Griffin ?> 66
  • 67. Update Example <?php $con = mysql_connect("localhost",“user_name",”password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_query("UPDATE Persons SET Age = '36' WHERE FirstName = 'Peter' AND LastName = 'Griffin'"); mysql_close($con); ?> Peter Griffin’s age was 35 Now age changed into 36 67
  • 68. Delete Example: <?php $con = mysql_connect("localhost",“user_name",“password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); mysql_query("DELETE FROM Persons WHERE LastName='Griffin'"); mysql_close($con); ?> 68
  • 69. WAMP Server (Apache, PHP, and MySQL) Installation 69
  • 70. Installation What do you need? Most people would prefer to install all-in-one solution: – WampServer -> for Windows platform Includes: • Apache 2.2.11 - MySQL 5.1.36 - PHP 5.3.0 • Download from http://www.wampserver.com/en/ – http://lamphowto.com/ -> for Linux platform 70
  • 71. Software to be used Wampserver (Apache, MySQL, PHP for Windows) WampServer provides a plateform to develop web applications using PHP, MySQL and Apache web server. After successful installation, you should have an new icon in the bottom right, where the clock is: 71
  • 73. Saving your PHP files Whenever you create a new PHP page, you need to save it in your WWW directory. You can see where this is by clicking its item on the menu: When you click on www directory You'll probably have only two files, index and testmysql. This www folder for Wampserver is usally at this location on your hard drive: c:/wamp/www/ 73