PHP Practical
PHP Practical
Program: -
<!DOCTYPE html>
<html>
<body>
<?php
$t = date("H");
} else {
?>
</body>
</html>
Output: -
2. Write a program using array which accepts five values and print the values.
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<?php
$a = array(1,2,3,4,5);
echo $a[$i]."<br>";
?>
</body>
</html>
Output: -
3. Write a program using Looping Structure with concept of Functions.
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<?php
function table($n)
table(5);
?>
</body>
</html>
Output: -
4. Write a program in PHP for type casting of a variable
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Practical-1</title>
</head>
<body>
<?php
$a = 12.5;
$k=(int)$a;
$k=(string)$a;
?>
</body>
</html>
Output: -
5. Write a program in PHP to display Multiplication Table using nested for loop.
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Practical-2</title>
</head>
<body>
<?php
$x = 5;
$y = 10;
echo "<br>";
?>
</body>
</html>
Output: -
6. Write a program In PHP to Sort an array using Bubble Sort function.
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Practical-3</title>
</head>
<body>
<?php
function bubble_Sort($my_array)
do
$swapped = false;
$swapped = true;
while( $swapped );
return $my_array;
?>
</body>
</html>
Output: -
7. Design the personal information form ,submit and retrieve the form data using php
$_POST,$_GET,$ REQUEST variable.
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Practical-4</title>
</head>
<body>
<form method="POST">
</form>
<?php
if (isset($_POST['submit']))
echo $_POST['full_name']."<br>";
echo $_POST['EmailID']."<br>";
echo $_POST['address']."<br>";
echo $_POST['mobile_no']."<br>";
}
?>
</body>
</html>
Output: -
8. Study of Cookies and Session In PHP.
a. Use of Cookies
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Practical-5(Cookies)</title>
</head>
<body>
<?php
if(isset($_COOKIE["category"]))
else
?>
</body>
</html>
Output: -
Use Of Session
i) P5_Session_Create
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Session Create</title>
</head>
<body>
<?php
session_start();
$_SESSION['username'] = "PHP";
$_SESSION['FavCat'] = "Books";
?>
</body>
</html>
Output: -
ii) P5_Session_Access
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Session Accessed</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['username']))
}
else
?>
</body>
</html>
Output: -
iii) P5_Session_Close
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<title>Session Closed</title>
</head>
<body>
<?php
session_start();
session_unset();
session_destroy();
?>
</body>
</html>
Output: -
9. Study Of Mysql DDL,DML,DCL Commands.
DDL(Data Definition Language): - DDL or Data Definition Language actually consists of the
SQL commands that can be used to define the database schema. It simply deals with descriptions
of the database schema and is used to create and modify the structure of database objects in the
database.
CREATE – is used to create the database or its objects (like table, index, function, views, store
procedure and triggers).
TRUNCATE–is used to remove all records from a table, including all spaces allocated for the
records are removed.
DML(Data Manipulation Language): - The SQL commands that deals with the manipulation
of data present in the database belong to DML or Data Manipulation Language and this includes
most of the SQL statements.
Examples of DML:
DCL(Data Control Language): - DCL includes commands such as GRANT and REVOKE
which mainly deal with the rights, permissions and other controls of the database system.
(Login Page)
Program: -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Form</title>
<style>
#LoginCon{
padding: 5px;
#formID{
#btn{
#pass{
margin: 1px 7px;
</style>
</head>
<body>
<div id = "LoginCon">
<label for="username">UserName</label>
<label for="password">Password</label>
</form>
</div>
</body>
</html>
(Login Validation)
Program: -
<?php
if (isset($_POST['submit']))
{
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "Practical";
$numRows = mysqli_num_rows($result);
$ststus = 0;
if($numRows > 0)
$i = 1;
$row = mysqli_fetch_assoc($result);
$ststus = 1;
break;
$i++;
if($ststus == 1)
echo "done";
else
?>
Output: -
11. Write a PHP code to create database and table in Mysql.
Program: -
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
if($result)
else
?>
(TO Create Table)
Program: -
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "Practical"
if($result)
else
?>
12. Write a PHP code to insert, delete, select the data from database.
Program: -
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "Practical";
if($result)
else
?>
(Delete data from database)
Program: -
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "Practical";
if($result)
else
?>
(SELECT Data From Table)
Program: -
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "Practical";
$i = 1;
$i++;
?>
Output: -
13. Design a from which upload & Display image in PHP
<html>
<head>
</head>
<body>
Select image :
</form>
<?php
if(isset($_POST['Submit1']))
if(move_uploaded_file($_FILES["file"]["tmp_name"], $filepath))
else
{
?>
</body>
</html>
Output: -
14. Write a PHP Code to make database connection, Create Data Base, Create Table In
Mysql.
Program: -
<?php
function Create_DB()
$servername = "localhost";
$username = "root";
$password = "123456";
if($result)
else
}
function Create_Table()
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "P14";
if($result)
else
Create_DB();
Create_Table();
?>
Output: -
15. Write a PHP code Insert, Delete, Update, Select the Data From Data Base.
Program: -
<?php
function Insert()
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "P14";
if($result)
else
function Delete()
{
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "P14";
if($result)
else
function Update()
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "P14";
if($result)
else
function Select()
$servername = "localhost";
$username = "root";
$password = "123456";
$database = "P14";
$Conn = mysqli_connect($servername, $username, $password, $database); //To form
connection with SQL
$i = 1;
// echo var_dump($row)."<br>"; //to print the array row form one by one
$i++;
Insert();
delete();
Update();
Select();
?>
Output: -