Professional Documents
Culture Documents
Usman Rafi
What is PHP?
PHP – an abbreviation
Stands for “Hyper Text Pre-Processor”
Programming Language
Used in Web Site Development
Used in Web Applications
Used for Server Side Scripting
Used to produce dynamic web pages
Object Oriented Language
Advantages of PHP
Light weight
Create page dynamically
Open source
Object oriented
Easy to understand
Rich in built-in functions
Why People Prefer ASP.NET over
PHP?
Easier development in ASP.NET
◦ Microsoft Visual Studio is an IDE that provides all
necessary facilities for developing professional web
sites using ASP.NET
◦ No proper editor is present for PHP
Multiple scripting languages
◦ ASP.NET has two powerful scripting languages
C# script
VB.NET script
◦ PHP itself is a single language for scripting
Way to Install
Way 1:
◦ Install PHP software
◦ Install MySQL software
◦ Configure both
◦ Lengthy and time consuming
◦ Requires effort to configure PHP
Way 2:
◦ Simplest way
◦ Download XAMPP control panel
◦ Install
◦ There you go!!!!!!!!!!
XAMPP Control Panel
Control panel provides various facilities
Contains facilities:
Concatenation Operator .
echo keyword is used to create output on page
◦ Single line //
◦ Multiline /* */
Variables
Temporary memory locations store data values
Not strongly typed
Variable can store anything
◦ Numeric values
◦ String values
◦ File names etc…………..
Syntax:
◦ Declared using dollar sign $
Example:
◦ $variable_name = value;
Loops and Conditional
All those used in C++, JAVA etc
Have same syntax as in above languages
Conditional Structure:
◦ if structure
◦ if else structure
◦ if else if else if … ladder
◦ select case
Looping:
◦ while loop
◦ do…while loop
◦ for loop
Create Dynamic Pages
echo
‘
Tag along with attributes and values
‘
;
Example
◦ Secure
◦ Invisible to others
Methodology (Form File)
Create a form
Set name, method, action attributes
Place form elements and name them in easy
way
Remember names
Place a button of submit type
Methodology (PHP Script File)
Open PHP tag
Place a check to find out whether submit
Name Controls
</form>
</body>
</html>
$_POST example STEP 2
<html>
<head>
<title>Form</title>
</head>
<body>
<form name=“sample” method=“post”
action=“handle.php” >
</form>
</body>
</html>
$_POST example STEP 3
<html>
<head>
<title>Form</title>
</head>
<body>
<form name=“sample” method=“post” action=“handle.php” >
Name:<input type=“text” />
<br/>
Age:<input type=“text” />
<br/>
<input type=“submit” />
</form>
</body>
</html>
$_POST example STEP 4
<html>
<head>
<title>Form</title>
</head>
<body>
<form name=“sample” method=“post” action=“handle.php” >
Name:<input type=“text” name=“txtname” />
<br/>
Age:<input type=“text” name=“txtage” />
<br/>
<input type=“submit” name=“btnsave” />
</form>
</body>
</html>
$_POST example STEP 5
<?php
?>
$_POST example STEP 6
<?php
if (isset($_POST[‘btnsave’]))
{
}
?>
$_POST example STEP 7
<?php
if (isset($_POST[‘btnsave’]))
{
$var_name = $_POST[‘txtname’];
$var_age = $_POST[‘’txtage];
echo “Your Name is:” . $var_name;
echo “Your Age is:” . $var_age;
}
?>
Bu
ilt
-i
n
Fu
nc
ti
on
s
Mostly Used Built-In
Functions
mysql_connect()
mysql_close()
mysql_pconnect()
mysql_error()
mysql_select_db()
mysql_query()
mysql_num_rows()
mysql_fetch_array()
mysql_connect() Function
Used to create a connection with the mysql
database server
Opens a connection to the database
◦ Connection variable
Example
◦ $conn =
mysql_connect(“server_name”,”user_name”,”passwo
rd”);
◦ mysql_close($conn);
mysql_pconnect() Function
Used to create a connection with the mysql
database server
Opens a connection to the database
Connection is automatically closed and opened
after executing the query
Requires three parameters:
◦ Server Name (Server Running the database)
◦ User Name (User Name for the database)
◦ Password (User Password for the database)
Example
◦ mysql_pconnect(“server_name”,”user_name”,”password”);
mysql_error() Function
Built-in function
Displays error description if unable to create
mysql databases
Requires two parameters
◦ Database Name
◦ Connection Name (Connection created)
Example
◦ Mysql_select_db(“database_name”,connection_varia
ble);
mysql_query() Function
Used to send SQL queries to the database for
manipulation of data
Returns result when SELECT query is send to the
database
Result is stored in variable
Requires a single parameter
◦ Query in string format
Example
◦ mysql_query(“Query Text”); (INSERT,UPDATE,DELETE
queries)
◦ $variable = mysql_query(“Query Text”); (SELECT query)
mysql_num_rows() Function
Used when SELECT query is used
Finds out the number of rows returned in the
the database
Requires one parameter
VALUES(‘4’,’Umair’,’04-04-
1995’,’55555’,’4444’)”;
mysql_query($query);
3 Rashid
Building DELETE Query in
PHP
All connection procedure
$parameter = ‘Rashid’;
$query = “DELETE * FROM `test` WHERE
`name` = ‘$parameter’;
To execute query
◦ mysql_query($query);
Building UPDATE Query in
PHP
All connection procedure
$oldname = ‘Rashid’;
$newname = ‘Afzal’;
$query = “UPDATE `test` SET `name` =
◦ mysql_query($query);
PHP Flow
Set name, method,
Create FORM Place Controls
action Attribute
Name Controls