0% found this document useful (0 votes)
44 views25 pages

PHP File

This document outlines several PHP programs that implement forms and form handling using Bootstrap styling. It includes programs to create a web form with validation and submission, a basic login form, and a CRUD application to manage a MySQL database of student records.

Uploaded by

ethicalishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views25 pages

PHP File

This document outlines several PHP programs that implement forms and form handling using Bootstrap styling. It includes programs to create a web form with validation and submission, a basic login form, and a CRUD application to manage a MySQL database of student records.

Uploaded by

ethicalishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

PRACTICAL – 1

Aim: The aim of this practical exercise is to implement a web form using PHP
and Bootstrap, enabling data collection with validation, submission handling,
and displaying the submitted data in a formatted manner.

Program :

index.php

<!DOCTYPE html> <html


lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include "header.php";?>

</head>
<body>
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#"> Bootstrap
</a>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search"
arialabel="Search">
<button class="btn btn-outline-success" type="submit">Search</button> </form>
</div>
</nav>

<form class="row g-3 needs-validation" action="form_data.php" method="post"


novalidate>
<div class="col-md-4">
<label for="validationCustom01" class="form-label">First Name</label>
<input type="text" class="form-control" name="fname" required>
<div class="valid-feedback"> Looks
good!
</div>
</div>
<div class="col-md-4">
<label for="validationCustom02" class="form-label">Last Name</label>
<input type="text" class="form-control" name="lname" required>
<div class="valid-feedback"> Looks
good!
</div>
</div>
<div class="col-md-4">
<label for="validationCustomUsername" class="form-
label">Username</label>
<div class="input-group has-validation">
<span class="input-group-text" id="inputGroupPrepend">@</span>
<input type="text" class="form-control" name="user"
id="validationCustomUsername" aria-describedby="inputGroupPrepend" required>
<div class="invalid-feedback"> Please
choose a username.
</div>
</div>
</div>
<div class="col-md-6">
<label for="validationCustom03" class="form-label">City</label>
<input type="text" class="form-control" name="city"
id="validationCustom03" required>
<div class="invalid-feedback"> Please
provide a valid city.
</div>
</div>
<div class="col-md-3">
<label for="validationCustom04" class="form-label">Education</label>
<select class="form-select" name="education" id="validationCustom04" required>
<option selected disabled value="">Choose Education</option>
<option>First Year</option>
<option>Second Year</option>
<option>Third Year</option>
</select>
<div class="invalid-feedback"> Please
select a valid state.
</div>
</div>
<div class="col-md-3">
<label for="validationCustom05" class="form-label">Pincode</label>
<input type="text" class="form-control" name="zipcode"
id="validationCustom05" required>
<div class="invalid-feedback"> Please
provide a valid pincode.
</div>
</div>
<div class="col-12">
<div class="form-check">
<input class="form-check-input" type="checkbox" value=""
id="invalidCheck" required>
<label class="form-check-label" for="invalidCheck"> Agree to
terms and conditions
</label>
<div class="invalid-feedback"> You must
agree before submitting.
</div>
</div>
</div>
<div class="col-12">
<button class="btn btn-primary" type="submit">Submit form</button> </div>
</form>
<br/><br/><br/><br/>
<?php include "footer_include.php"; ?>
</body>
</html>

form_data.php
<!DOCTYPE html> <html
lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include "header.php";?>
</head> <body>
<?php
// print_r($_POST);
echo "<h1>Hello ". $_POST["fname"]." ".$_POST["lname"]." ! </h1><br/> ";
?>
<div class="card" style="width: 18rem;">
<div class="card-header">
<?php echo $_POST["user"]; ?>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"><?php echo $_POST["city"]; ?></li>
<li class="list-group-item"><?php echo $_POST["education"]; ?></li>
<li class="list-group-item"><?php echo $_POST["zipcode"]; ?></li> </ul>
</div>
<br/><br/><br/><br/>
<?php include "footer_include.php"; ?>
</body>
</html>

header.php
<head>
<title>PHP DEMO</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
crossorigin="anonymous">

</head>

footer_include.php
<footer>
&copy; 2012 - <?php echo date("Y"); ?>
</footer> <script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min. js"
integrity="sha384-
u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8"
crossorigin="anonymous"></script>
PRACTICAL – 2

Aim: This exercise aims to build a basic login form utilizing HTML,
Bootstrap for styling, and PHP for form handling. Upon submission,
form_handler.php processes the data, displays a thank-you message, and
showcases the submitted information, including email,password,
and gender. Basic validation ensures mandatory fields are filled in.

Program: form1.php

<!DOCTYPE html>
<html>
<head>
<title>A Simple Login Form</title>
<?php include "header.php" ;?>

</head>
<body>
<form action="form_handler.php" method="get">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" name="exampleInputEmail1"
id="exampleInputEmail1" aria-describedby="emailHelp">
<div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" class="form-control" name="exampleInputPassword1"
id="exampleInputPassword1">
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label> </div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault"
id="flexRadioDefault1" value="F">
<label class="form-check-label" for="flexRadioDefault1">
Female
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault"
id="flexRadioDefault2" value="M" checked>
<label class="form-check-label" for="flexRadioDefault2">
Male
</label>
</div>

<button type="submit" class="btn btn-primary">Submit</button>


</form>

</body>
</html>

form_handler.php
<!DOCTYPE html>
<html>
<head>
<title>Thank You</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
</head>
<body>
<h1>Thank You</h1>
<p>Thank you for registering. Here is the information you submitted:</p>

First name: <?php


if(!isset($_GET["exampleInputEmail1"])){
echo "Name is mandatory";
} else { echo $_GET["exampleInputEmail1"];
}
?> <br/>
Password: <?php
if(!isset($_GET["exampleInputPassword1"])){
echo "Password shold not be blank";
} else{ echo $_GET["exampleInputPassword1"];
}
?><br/>
Gender: <?php echo $_GET["flexRadioDefault"];
?>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>
header.php
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
PRACTICAL – 3
Aim: The aim of this project is to create a simple CRUD (Create, Read, Update,
Delete) application for managing student records in a MySQL database. This
involves implementing PHP scripts for adding, updating, deleting, and displaying student
information, along with basic styling using Bootstrap.

Program: connect.php

<?php
$servername = "localhost"; // Replace with your server name
$username = "root"; // Replace with your MySQL username
$password = ""; // Replace with your MySQL password
$database = "crud"; // Replace with your MySQL database name

// Create connection
$conn = new mysqli($servername, $username, $password, $database, 3307);
if(!$conn){
//echo "connection successfull";
die(mysqli_error($conn));
echo "connection unsuccessfull";
}
?>

delete.php
<?php

include 'connect.php';
if(isset($_GET['deleterno'])){
$rno = $_GET['deleterno'];

$sql = "delete from `db` where rollno=$rno";


$result = mysqli_query($conn, $sql);

if($result){
// echo 'Deleted Successfully!';
header('location:display.php');
} else {
die(mysqli_error($conn));
}
}

?>
display.php

<?php
include 'connect.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CRUD Data</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<button class="btn btn-primary my-5">
<a href="user.php" class="text-light">Add User</a>
</button>

<table class="table">
<thead>
<tr>
<th>Student Name</th>
<th>Class</th>
<th>Student Number</th>
<th>Address</th>
<th>Operations</th>
</tr>
</thead>
<tbody>

<?php
$sql = "select * from `db`";
$result = mysqli_query($conn, $sql);
if($result){
// $row = mysqli_fetch_assoc($result);
// echo $row['name'];
while($row = mysqli_fetch_assoc($result)){
$rollno = $row['rollno'];
$name = $row['name'];
$class = $row['class'];
$address = $row['address'];
echo '<tr>
<th scope="row">'.$rollno.'</th>
<td>'.$name.'</td>
<td>'.$class.'</td>
<td>'.$address.'</td>
<td>
<button class="btn btn-primary"><a href="update.php?updaterno='.$rollno.'" class="text-
light">Update</a></button>
<button class="btn btn-danger"><a href="delete.php?deleterno='.$rollno.'" class="text-
light">Delete</a></button>
</td>
</tr>';
}
}

?>

</tbody>
</table>

</div>
</body>
</html>

update.php
<?php
include 'connect.php';
$rno = $_GET['updaterno'];
$sql = "select * from `db` where rollno=$rno";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);

$name = $row['name'];
$class = $row['class'];
$rollno = $row['rollno'];
$address = $row['address'];

if(isset($_POST['submit'])){
$name = $_POST['name'];
$class = $_POST['class'];
$rollno = $_POST['rollno'];
$address = $_POST['address'];

$sql = "update `db` set rollno=$rno, name='$name', class='$class',


address='$address' where rollno=$rno";

$result = mysqli_query($conn, $sql);

if($result){
// echo "Data Updated successfully...";
header('location:display.php');
} else {
die(mysqli_error($conn));
}
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CRUD operation</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>

<body>
<div class="container">
<h1 class="text-center">Welcome to student portal!</h1>
</div>

<div class="container my-5">


<form method="post">
<div class="form-group">
<label>Student Name:</label>
<input type="text" name="name" class="form-control" autocomplete="off" value=<?php
echo $name; ?>>
</div>
<div class="form-group">
<label>Class:</label>
<input type="text" name="class" class="form-control" autocomplete="off" value=<?php
echo $class; ?>>
</div>
<div class="form-group">
<label>Roll no:</label>
<input type="text" name="rollno" class="form-control" autocomplete="off" value=<?php
echo $rollno; ?>>
</div>
<div class="form-group">
<label>Address:</label>
<input type="text" name="address" class="form-control" autocomplete="off"
value=<?php echo $address; ?>>
</div><br/>
<button type="submit" name="submit" class="btn btn-primary">Update</button>
</form>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>

user.php

<?php
include 'connect.php';

if(isset($_POST['submit'])){
$name = $_POST['name'];
$class = $_POST['class'];
$rollno = $_POST['rollno'];
$address = $_POST['address'];

$sql = "insert into `db` (name, class, rollno, address)


values('$name', '$class', '$rollno', '$address')";

$result = mysqli_query($conn, $sql);

if($result){
//echo "Data inserted successfully...";
header('location:display.php');
} else {
die(mysqli_error($conn));
}
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CRUD operation</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>

<body>
<div class="container">
<h1 class="text-center">Welcome to student portal!</h1>
</div>

<div class="container my-5">


<form method="post">
<div class="form-group">
<label>Student Name:</label>
<input type="text" name="name" class="form-control" autocomplete="off">
</div>
<div class="form-group">
<label>Class:</label>
<input type="text" name="class" class="form-control" autocomplete="off">
</div>
<div class="form-group">
<label>Roll no:</label>
<input type="text" name="rollno" class="form-control" autocomplete="off">
</div>
<div class="form-group">
<label>Address:</label>
<input type="text" name="address" class="form-control" autocomplete="off">
</div><br/>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>

</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>

Db.sql

-- phpMyAdmin SQL Dump


-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3307
-- Generation Time: Mar 26, 2024 at 07:54 PM
-- Server version: 10.4.28-MariaDB
-- PHP Version: 8.2.4

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";


START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `crud`
--

-- --------------------------------------------------------

--
-- Table structure for table `db`
--

CREATE TABLE `db` (


`name` varchar(30) NOT NULL,
`class` varchar(20) NOT NULL,
`rollno` varchar(10) NOT NULL,
`address` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `db`
--

INSERT INTO `db` (`name`, `class`, `rollno`, `address`) VALUES


('vishal', 'BCS', '2', 'MIT'),
('Akshay', 'BCS', '01', 'Kamgar Chowk'),
('XYZ', 'BCS SY', '05', 'Kranti Chowk'),
('Sanika', 'Bsc IT', '10', 'Sillod');
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;


/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
PRACTICAL – 4

Aim: The aim of this project is to develop a basic web application for user
registration and authentication. It includes functionalities such as user sign-
up (sign.php), login (login.php), and logout (logout.php).

Program:

connect.php

<?php
$servername = "localhost"; // Replace with your server name
$username = "root"; // Replace with your MySQL username
$password = ""; // Replace with your MySQL password
$database = "emp"; // Replace with your MySQL database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database, 3307);
if(!$conn){
die(mysqli_error($conn)); // echo "connection successfull";
}
?>

Home.php

<?php
session_start();
if(!isset($_SESSION['empname'])){
header('location:login.php');
}

?>

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->


<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">

<title>Welcome Page</title>
</head>
<body>
<h1 class="text-center mt-5">Hello, <?php echo $_SESSION['empname']; ?></h1>
<div class="container">
<a href="logout.php" class="btn btn-primary mt-5">Logout</a>
</div>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
crossorigin="anonymous"></script>
-->
</body>
</html>

login.php
<?php
$login = 0;
$invalid = 0;
//echo $user;
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'connect.php';
$name = $_POST['empname'];
$pass = $_POST['emppass'];

$sql = "select * from `rst` where


empname= '$name' and emppass='$pass'";

$result = mysqli_query($conn, $sql);

if($result){
$num = mysqli_num_rows($result);
if($num>0){
// echo 'Login Successful';
$login = 1;
// create a session
session_start();
$_SESSION['empname'] = $name;
header('location:home.php');
} else {
// echo 'Invalid Data';
$invalid = 1;
}
}
}
?>

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->


<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">

<title>Login Page</title>
</head>
<body>

<?php
if($login){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success!</strong> You have successfully login.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<?php
if($invalid){
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error !</strong> Invalid Credentials.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<div class="container my-5">
<h1 class="text-center">Login to our Page </h1>
<form action="login.php" method="post">
<div class="mb-3">
<label class="form-label">User Name:</label>
<input type="text" class="form-control" name="empname" placeholder="Enter user
name:">
</div>
<div class="mb-3">
<label class="form-label">Password:</label>
<input type="password" class="form-control" name="emppass" placeholder="Enter your
Password" >
</div>

<button type="submit" class="btn btn-primary">Login</button>


</form>
</div>

<!-- Option 1: Bootstrap Bundle with Popper -->


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>

sign.php
<?php
$success = 0;
$user = 0;
//echo $user;
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'connect.php';
$name = $_POST['empname'];
$pass = $_POST['emppass'];

$sql = "select * from `rst` where


empname= '$name'";

$result = mysqli_query($conn, $sql);

if($result){
$num = mysqli_num_rows($result);
if($num>0){
// echo 'User already exists!';
$user = 1;
// echo $user;
} else {
$sql = "insert into `rst` (empname, emppass) values('$name', '$pass')";
$result = mysqli_query($conn, $sql);
if($result){
//echo "SignUp successfully!";
$success = 1;
$user = 0;
} else {
die(mysqli_error($conn));
}
}
}
}
?>

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->


<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">

<title>Sign Up Page</title>
</head>
<body>
<?php
if($success){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Successful !</strong> You have created account successfully.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<?php
if($user){
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Sorry !</strong> User Already exists...
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>

<div class="container my-5">


<h1 class="text-center">Sign Up </h1>
<form action="sign.php" method="post">
<div class="mb-3">
<label class="form-label">User Name:</label>
<input type="text" class="form-control" name="empname" placeholder="Enter user
name:">
</div>
<div class="mb-3">
<label class="form-label">Password:</label>
<input type="password" class="form-control" name="emppass" placeholder="Enter your
Password" >
</div>

<button type="submit" class="btn btn-primary">Sign Up</button>


</form>
</div>

<!-- Option 1: Bootstrap Bundle with Popper -->


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>

logout.php
<?php
session_start(); session_destroy();

header('location:login.php');
?>

Emp.sql

-- phpMyAdmin SQL Dump


-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3307
-- Generation Time: Mar 26, 2024 at 07:54 PM
-- Server version: 10.4.28-MariaDB
-- PHP Version: 8.2.4

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";


START TRANSACTION;
SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;


/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `emp`
--

-- --------------------------------------------------------

--
-- Table structure for table `rst`
--

CREATE TABLE `rst` (


`empname` varchar(20) NOT NULL,
`empid` varchar(10) NOT NULL,
`emppass` varchar(15) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;


/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
PRACTICAL – 5

Aim: The aim of this project is to demonstrate the usage of cookies in PHP. It
involves creating a cookie named "Brave" with the value "Google" and then
retrieving and displaying the cookie's value on the webpage.

Program : cookie.php

<?php
// create cookie with PHP (must be before html tag)
$cookie_name = "Brave";
$cookie_value = "ABCD";
setcookie($cookie_name, $cookie_value, time() + (86400 * -1), "/" );
# to set and modify cookie use the same function.
# to delete the cookie usef same function with past date.

?>

<html>
<body>
<?php
include '03header.php';

if(!isset($_COOKIE[$cookie_name])){
echo "Cookie named " . $cookie_name . " is not set!";
} else {
echo "Cookie " . $cookie_name . " is set. <br>";
echo "Value is ". $_COOKIE[$cookie_name];
}

include '02footer_include.php';
?>
</body>
</html>

header.php
<head>
<title>PHP DEMO</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
crossorigin="anonymous">

</head>

02footer_include.php
<!-- To print automatically copyright year-->
<footer>
&copy; 2012 - <?php echo date("Y"); ?>
</footer> <script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8"
crossorigin="anonymous"></script>
PRACTICAL – 6

Aim: The aim of this project is to illustrate the usage of sessions in PHP. It
starts by initiating a session, unsetting all session variables, and then
destroying the session. Subsequently, it sets session variables ("user" and
"pwd") and displays a message confirming their assignment. The project
employs PHP for session management and includes Bootstrap for basic
styling.

Program:

07session.php
<?php
// start a session
// it must be the very first thing in your document, before any html tags
session_start(); // imp functions echo session_id()."<br>"; echo
session_name(). "<br>"; // to remove all session variables
session_unset(); // to
destroy session
session_destroy();
?>
<!DOCTYPE html>
<html>
<?php include '03header.php';?>
<body>
<?php
// set session variables.
$_SESSION["user"] = "Brave";
$_SESSION["pwd"] = "Pass"; echo "session
variables are set !"; include
'02footer_include.php';
?>
</body> </html>

03header.php
<head>
<title>PHP DEMO</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
crossorigin="anonymous">

</head>
02footer_include.php
<!-- To print automatically copyright year-->
<footer>
&copy; 2012 - <?php echo date("Y"); ?>
</footer> <script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8"
crossorigin="anonymous"></script>

You might also like