PHP Lab Programs
PHP Lab Programs
<html>
<head>
<title>SUM OF DIGITS </title>
</head>
<body>
<form method="POST">
Enter the number for the sum of digits:<input type="number" name="num"><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
if(isset($_POST['submit']))
{
$a=$_POST['num'];
$num1=$a;
sum=0;
while($a>1)
{
$rem=$a%10;
$a=$a/10;
$sum= $sum + $rem;
}
echo "Sum of given digit ".$num1." is: ".$sum;
}
?>
</body>
</html>
1
OUTPUT:
RESULT:
Thus, the above sum of digit program has been executed successfully and verified the
output.
2
PROGRAM: INSERT A NEW ITEM IN AN ARRAY
<html>
<head>
<title>Inserting a New item in an Array</title>
</head>
<body>
<form method="POST">
Enter the Element : <input type="text" name="no"><br>
Enter the Position: <input type="number" name="ind"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$a=$_POST['no'];
$i=$_POST['ind'];
$original = array( '1','2','3','4','5' );
echo 'Original array : '."\n";
foreach ($original as $x)
{
echo "$x ";
}
array_splice( $original, $i, 0, $a );
echo "<br>";
echo "\n After inserting ".$a." the array is : ";
foreach ($original as $x)
3
{
echo "$x ";
}
echo "<br>";
}
?>
4
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
5
PROGRAM: SORTING ARRAY VALUES AND KEYS
<?php
$people = array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");
$temp = "";
function display($array)
{
foreach($array as $p => $a)
{
echo " Age of ".$p." is : ".$a;
echo"<br>";
}
}
echo"Sorted by Value, Ascending:<br>";
asort($people);
display($people);
echo"<br>";
echo"<br>";
6
echo"<br>";
echo"<br>";
echo"Sorted by Key, Descending:<br>";
krsort($people);
display($people);
echo"<br>";
echo"<br>";
echo"String to Uppercase:<br>";
$temp = array_change_key_case($people, CASE_UPPER);
display($temp);
echo"<br>";
echo"<br>";
echo"String to Lowercase:<br>";
$temp = array_change_key_case($people, CASE_LOWER);
display($temp);
echo"<br>";
echo"<br>";
7
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
8
PROGRAM: DISPLAY A CHESS BOARD
<html>
<head>
<title>Chess Board</title>
</head>
<body>
<h3>Chess Board using Nested For Loop</h3>
<table width="270px" cellspacing="0px" cellpadding="0px" border="1px">
<?php
for($row=1;$row<=8;$row++)
{
echo "<tr>";
for($col=1;$col<=8;$col++)
{
$total=$row+$col;
if($total%2==0)
{
echo "<td height=30px width=30px bgcolor=#FFFFFF></td>";
}
else
{
echo "<td height=30px width=30px bgcolor=#000000></td>";
}
}
echo "</tr>"
}?>
</table>
</body>
</html>
9
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
10
PROGRAM: SQUARE ROOT OF A NUMBER
<html>
<head>
<title>Square root of a Given Number</title>
</head>
<body>
<form method="post">
Enter a number
<input type="text" name="input" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit']))
{
$input = $_POST['input'];
$val = sqrt($input);
echo 'The square root of '.$input.' = '.$val;
}
?>
</body>
</html>
11
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
12
PROGRAM: FIBONACCI SERIES
<html>
<head>
<title>Fibonacci series of a given number</title>
</head>
<body>
<form method="post">
Enter the Number :
<input type="text" name="num1" placeholder="Enter a number"/> <br>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
function fibo($n)
{
if ($n == 0)
return 0;
elseif ($n == 1)
return 1;
else
return (fibo($n-1) + fibo($n-2));
}
if(isset($_POST['submit']))
{
$n = $_POST['num1'];
echo "Fibonacci series of $n is : ";
for ($c = 0; $c < $n; $c++)
{
13
echo fibo($c),' ';
}
return 0;
}
?>
</body>
</html>
14
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output
15
PROGRAM: BIRTHDAY COUNTDOWN
<html>
<head>
<title> Birthday Count down</title>
</head>
<body>
<h2>COUNT FOR NEXT BIRTHDAY</h2>
<form method="post">
ENTER YOUR DATE OF BIRTH :<input type="text" name="dob"
Placeholder="Enter Here">
<input type="submit" name="submit" Value="submit">
</form> <br>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['dob'];
$m = substr($n,0,2);
$d = substr($n,3,2);
$y = substr($n,6,4);
$target_days = mktime(0,0,0,$m,$d,$y);
$today = time();
$diff_days = ($target_days - $today);
$days = (int)($diff_days/86400);
echo "Date of Birth : $n";
echo "<br>";
echo "Days till next birthday : $days days!";
}?>
</body>
16
</html>
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
17
PROGRAM: COOKIE (LAST VISITED DATE & TIME)
<html>
<head>
<title>COOKIE</title>
</head>
<body>
<?php
echo "<h2>wecome</h2>";
if(isset($_COOKIE['lastvisit']) )
{
echo "<h3>Hi $_COOKIE[username]! Welcome back!<br>You last visited
on $_COOKIE[lastvisit]</h3>";
}
else
{
Setcookie('username', 'User',time()+30*24*60*60 );
Setcookie('lasvisit',date('M d,Y,h:m a'),time()+30*24*60*60);
}
?>
</body>
</html>
18
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
19
PROGRAM: UPLOAD AND DISPLAY IMAGE
PARTICULAR DIRECTORY
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<div style=" margin-top:50px; ">
<h2><U> UPLOAD AND DISPLAY AN IMAGE IN PARTICULAR DIRECTORY
</U></h2></br>
<form method="post" enctype="multipart/form-data">
<b>Select any Image:
<input type="file" name="image">
<input type="submit" name="submit" value="Upload"></br></br>
</form>
<?php
if(isset($_POST['submit']))
{
$imagename = $_FILES['image']['name'];
$imageTempName = $_FILES['image']['tmp_name'];
$target_file = '/photos/'.$imagename;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
21
OUTPUT:
RESULT:
Thus, the above program has been executed successfully and verified the output.
22
PROGRAM: STUDENT DETAILS DATABASE
STYLE.CSS:
body {font-family:Arial, Sans-Serif;}
.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
a {color:#0067ab; text-decoration:none;}
a:hover {text-decoration:underline;}
.form{width: 500px; margin: 0 auto;}
input[type='submit']
{padding: 10px 25px 8px; color: #fff; background-color: #0067ab;
text-shadow: rgba(0,0,0,0.24) 0 1px 0; font-size: 16px;
box-shadow: rgba(255,255,255,0.24) 0 2px 0 0 inset,#fff 0 1px 0 0;
border: 1px solid #0164a5; border-radius: 2px; margin-top:
10px; cursor:pointer;}
AUTH.PHP:
<?php
session_start();
if(!isset($_SESSION["username"]))
{
header("Location: login.php");
exit();
23
}?>
REGISTRATION.PHP:
<!DOCTYPE html>
<html>
<head>
<!--<meta charset="utf-8">-->
<title style>Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
if(isset($_POST['submit']))
{
$username = $_REQUEST['username'];
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into users (username, password, email, trn_date) VALUES
('$username', '".md5($password)."', '$email', '$trn_date')";
$result = mysqli_query($con,$query);
if($result)
{
echo "<div class='form'><h3>You are registered successfully.
</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}
else
{
24
?></br></br><div class="form" style ="text-align:center;"></br></br>
<h1><u>Registration</u></h1></br></br>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username"
required /></br></br>
<input type="email" name="email" placeholder="Email" required
/></br></br>
<input type="password" name="password" placeholder="Password"
required /></br></br>
<input type="submit" name="submit" value="Register" /></br></br>
</form>
<p>Already registered? <a href='login.php'>Login Here</a></p>
</br></br>
</div><?php
}?>
</body>
</html>
LOGIN.PHP:
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
session_start();
if (isset($_POST['username']))
{
25
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$query = "SELECT * FROM users WHERE username='$username' and
password='".md5($password)."'";
$result = mysqli_query($con,$query) or die(mysqli_error());
$rows = mysqli_num_rows($result);
if($rows==1)
{
$_SESSION['username'] = $username;
header("Location: insert.php"); // Redirect user to insert.php
}
else{
echo '<script>alert(" Username/password is incorrect. Please insert
valid input")</script>';
header("Refresh:0; url=login.php");
}
}
else{?>
</br></br>
<div class="form" style ="text-align:center; background-color:powderblue;" >
</br></br><h1><u> LOG IN </u></h1><br><br>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username"
required /></br></br>
<input type="password" name="password" placeholder=
"Password" required /></br></br>
<input name="submit" type="submit" value="Login" />
</br></br></br>
</form><p>Not registered yet? <a href='registration.php'>
Register Here</a></p></br></br>
26
</div>
<?php
}?>
</body>
</html>
DB.PHP:
<?php
$con = mysqli_connect("localhost","root","","studentdb");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}?>
INSERT.PHP:
<?php
require('db.php');
include("auth.php");
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$trn_date = date("Y-m-d H:i:s");
$firstname =$_REQUEST['fname'];
$lastname =$_REQUEST['lname'];
$email =$_REQUEST['mailid'];
$phone = $_REQUEST['phone'];
$course = $_REQUEST['course'];
$year = $_REQUEST['year'];
$grade = $_REQUEST['grade'];
$submittedby = $_SESSION["username"];
27
$ins_query="insert into student (trn_date,first_name,last_name,email,
phone,course,year,grade,submittedby) values ('$trn_date','$firstname',
'$lastname','$email','$phone','$course','$year','$grade','$submittedby')";
mysqli_query($con,$ins_query) or die(mysqli_error($con));
$status = "New Record Inserted Successfully.</br></br>";
}?>
<a href = "view.php"> View Inserted Record</a>
<!DOCTYPE html>
<html>
<head>
<!-- <meta charset="utf-8"> -->
<title>Insert New Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div style="text-align:center; margin-center:20px; margin-top:50px; margin-
bottom:5px ;font-size:10pt">
<h2> <a href="insert.php"> INSERT NEW </a> |
<a href="view.php"> VIEW RECORDS </a> |
<a href="logout.php" > LOGOUT </a></h2>
<h1>Insert New Record</h1>
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1"/>
FIRST NAME : <input type="text" name="fname" required /></br>
LAST NAME: <input type="text" name="lname" required /></br>
COURSE : <input type="text" name="course" required /></br>
YEAR : <input type="text" name="year"
required /></br>
GRADE : <input
type="text" name="grade" required /></br>
28
EMAIL ID : <input
type="email" name="mailid" required /></br>
PHONE NO. : <input type="text"
name="phone" required /></br>
<p><input name="submit" type="submit" value=" INSERT " /></p>
</form>
<p style="color:#FF0000;"><?php echo $status; ?></p></div>
</body>
</html>
EDIT.PHP:
<?php
require('db.php');
include("auth.php");
$id=$_REQUEST['id'];
$query = "SELECT * from student where id='".$id."'";
$result = mysqli_query($con, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Update Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div style="text-align:center; margin-center:20px; margin-top:50px; margin-
bottom:5px ;font-size:10pt">
<h2> <a href="insert.php"> INSERT NEW </a> |
29
<a href="view.php"> VIEW RECORDS </a> |
<a href="logout.php"> LOGOUT </a></h2>
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$id=$_REQUEST['id'];
$trn_date = date("Y-m-d H:i:s");
$firstname =$_REQUEST['fname'];
$lastname =$_REQUEST['lname'];
$email =$_REQUEST['mailid'];
$phone = $_REQUEST['phone'];
$course = $_REQUEST['course'];
$year = $_REQUEST['year'];
$grade = $_REQUEST['grade'];
$submittedby = $_SESSION["username"];
$update="update student set trn_date='".$trn_date."', first_name='"
.$firstname."', last_name='".$lastname."', email='".$email."', phone=
'".$phone."', course='".$course."', year='".$year."', grade='".$grade."',
submittedby='".$submittedby."' where id='".$id."'";
mysqli_query($con, $update) or die(mysqli_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View
Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}
else
{
?><h1>Update Record</h1>
<div><form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
30
FIRST NAME : <input type="text" name="fname" value="<?php echo
$row['first_name'];?>" /></br>
LAST NAME : <input type="text" name="lname" value="<?php echo
$row['last_name'];?>" /></br>
COURSE : <input type="text" name="course" value="<?php echo
$row['course'];?>" /></br>
YEAR : <input type="text" name="year"
value="<?php echo $row['year'];?>" /></br>
GRADE : <input type="text" name="grade"
value="<?php echo $row['grade'];?>" /></br>
EMAIL ID : <input type="email" name="mailid"
value="<?php echo $row['email'];?>" /></br>
PHONE NO. : <input type="text" name="phone" value="<?php echo
$row['phone'];?>" /></br>
<p><input name="submit" type="submit" value=" UPDATE " /></p>
</form>
<?php
}
?>
</div></div>
</body>
</html>
DELETE.PHP:
<?php
require('db.php');
$id=$_REQUEST['id'];
$query = "DELETE FROM student WHERE id=$id";
$result = mysqli_query($con,$query) or die ( mysqli_error());
header("Location: view.php");
31
?>
VIEW.PHP:
<?php
require('db.php'); include("auth.php");
?>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div style="text-align:center; margin-center:20px; margin-top:50px; margin-
bottom:5px ;font-size:10pt">
<h2> <a href="insert.php"> INSERT NEW </a> |
<a href="view.php"> VIEW RECORDS </a> |
<a href="logout.php"> LOGOUT </a></h2><br>
<h2>VIEW RECORDS</h2><br>
<table align="center" width="60%" border="2" style="border-collapse:collapse;">
<thead>
<tr>
<th><strong> S.NO </strong></th>
<th><strong> FIRST NAME </strong></th>
<th><strong> LAST NAME </strong></th>
<th><strong> COURSE </strong></th>
<th><strong> YEAR </strong></th>
<th><strong> GRADE </strong></th>
<th><strong> EMAIL ADDRESS </strong></th>
32
<th><strong> PHONE NO </strong></th>
<th><strong> EDIT </strong></th>
<th><strong> DELETE </strong></th>
</tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select * from student ORDER BY id asc;";
$result = mysqli_query($con,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr align="center">
<td><?php echo $count; ?></td>
<td><?php echo $row["first_name"]; ?></td>
<td><?php echo $row["last_name"]; ?></td>
<td><?php echo $row["course"]; ?></td>
<td><?php echo $row["year"]; ?></td>
<td><?php echo $row["grade"]; ?></td>
<td><?php echo $row["email"]; ?></td>
<td><?php echo $row["phone"]; ?></td>
<td><a href="edit.php?id=<?php echo $row["id"]; ?>">Edit</a></td>
<td><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a>
</td>
</tr>
<?php $count++; } ?>
</tbody>
</table></div>
</body>
</html>
33
LOGOUT.PHP:
<?php
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: login.php"); // Redirecting To Home Page
}
?>
OUTPUT:
PHPMYADMIN:
REGISTRATION:
34
LOGIN:
INSERT:
35
UPDATE:
36
VIEW:
DELETE:
37
RESULT:
Thus, the above program has been executed successfully and verified the output.
38
PROGRAM: EMPLOYEE DETAILS DATABASE
STYLE.CSS:
body {font-family:Arial, Sans-Serif;}
.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
a {color:#0067ab; text-decoration:none;}
a:hover {text-decoration:underline;}
.form{width: 500px; margin: 0 auto;}
input[type='text'], input[type='email'], input[type='password'], input[type='number']
{width: 200px; border-radius: 2px;border: 1px solid #CCC;
padding: 10px; color: #333; font-size: 14px; margin-top: 10px;}
input[type='submit']
{padding: 10px 25px 8px; color: #fff; background-color: #0067ab;
text-shadow: rgba(0,0,0,0.24) 0 1px 0; font-size: 16px;
box-shadow: rgba(255,255,255,0.24) 0 2px 0 0 inset,#fff 0 1px 0 0;
border: 1px solid #0164a5; border-radius: 2px; margin-top:
10px; cursor:pointer;}
AUTH.PHP:
<?php
session_start();
if(!isset($_SESSION["username"]))
{
header("Location: login.php");
exit();
}?>
39
REGISTRATION.PHP:
<!DOCTYPE html>
<html>
<head>
<!--<meta charset="utf-8">-->
<title style>Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
if(isset($_POST['submit']))
{
$username = $_REQUEST['username'];
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into users (username, password, email, trn_date) VALUES
('$username', '".md5($password)."', '$email', '$trn_date')";
$result = mysqli_query($con,$query);
if($result)
{
echo "<div class='form'><h3>You are registered successfully.
</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}
else
{
?>
</br></br><div class="form" style ="text-align:center;"></br></br>
40
<h1><u>Registration</u></h1></br></br>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username"
required /></br></br>
<input type="email" name="email" placeholder="Email" required
/></br></br>
<input type="password" name="password" placeholder="Password"
required /></br></br>
<input type="submit" name="submit" value="Register" /></br></br>
</form>
<p>Already registered? <a href='login.php'>Login Here</a></p>
</br></br>
</div>
<?php
}
?>
</body>
</html>
LOGIN.PHP:
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
session_start();
if (isset($_POST['username']))
41
{
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$query = "SELECT * FROM users WHERE username='$username' and
password='".md5($password)."'";
$result = mysqli_query($con,$query) or die(mysqli_error());
$rows = mysqli_num_rows($result);
if($rows==1)
{
$_SESSION['username'] = $username;
header("Location: insert.php"); // Redirect user to insert.php
}
else
{
echo '<script>alert(" Username/password is incorrect. Please insert
valid input")</script>';
header("Refresh:0; url=login.php");
}
}
else
{
?>
</br></br>
<div class="form" style ="text-align:center; background-color:powderblue;" >
</br></br><h1><u> LOG IN </u></h1><br><br>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username"
required /></br></br>
<input type="password" name="password" placeholder=
"Password" required /></br></br>
42
<input name="submit" type="submit" value="Login" />
</br></br></br>
</form>
<p>Not registered yet? <a href='registration.php'>
Register Here</a></p></br></br>
</div>
<?php
}?>
</body>
</html>
DB.PHP:
<?php
$con = mysqli_connect("localhost","root","","studentdb");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
INSERT.PHP:
<?php
require('db.php');
include("auth.php");
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$trn_date = date("Y-m-d H:i:s");
$empno =$_REQUEST['empno'];
$empame =$_REQUEST['empname'];
$email =$_REQUEST['mailid'];
43
$phone = $_REQUEST['phone'];
$depno = $_REQUEST['depno'];
$desig = $_REQUEST['desig'];
$salary = $_REQUEST['salary'];
$submittedby = $_SESSION["username"];
$ins_query="insert into employee (trn_date,empno,empname,email,
phone,depno,desig,salary,submittedby) values ('$trn_date','$empno',
'$empname','$email','$phone','$depno','$desig','$salary','$submittedby')";
mysqli_query($con,$ins_query) or die(mysqli_error($con));
$status = "New Record Inserted Successfully.</br></br>";
}
?>
<a href = "view.php"> View Inserted Record</a>
<!DOCTYPE html>
<html>
<head>
<!-- <meta charset="utf-8"> -->
<title>Insert New Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div style="text-align:center; margin-center:20px; margin-top:50px; margin-
bottom:5px ;font-size:10pt">
<h2> <a href="insert.php"> INSERT NEW </a> |
<a href="view.php"> VIEW RECORDS </a> |
<a href="logout.php" > LOGOUT </a></h2>
<h1>Insert New Record</h1>
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1"/>
EMPLOYEE NO : <input type="text" name="empno" required /></br>
44
EMPLOYEE NAME: <input type="text" name="empname" required /></br>
DEPARTMENT NO: <input type="text" name="depno" required /></br>
DESIGNATION : <input type="text" name="desig"
required /></br>
SALARY : <input
type="text" name="salary" required /></br>
EMAIL ID : <input
type="email" name="mailid" required /></br>
PHONE NO. : <input type="text"
name="phone" required /></br>
<p><input name="submit" type="submit" value=" INSERT " /></p>
</form>
<p style="color:#FF0000;"><?php echo $status; ?></p></div>
</body>
</html>
EDIT.PHP:
<?php
require('db.php');
include("auth.php");
$id=$_REQUEST['id'];
$query = "SELECT * from employee where id='".$id."'";
$result = mysqli_query($con, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Update Record</title>
45
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div style="text-align:center; margin-center:20px; margin-top:50px; margin-
bottom:5px ;font-size:10pt">
<h2> <a href="insert.php"> INSERT NEW </a> |
<a href="view.php"> VIEW RECORDS </a> |
<a href="logout.php"> LOGOUT </a></h2>
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$id=$_REQUEST['id'];
$trn_date = date("Y-m-d H:i:s");
$empno =$_REQUEST['empno'];
$empname =$_REQUEST['empname'];
$email =$_REQUEST['mailid'];
$phone = $_REQUEST['phone'];
$depno = $_REQUEST['depno'];
$desig = $_REQUEST['desig'];
$salary = $_REQUEST['salary'];
$submittedby = $_SESSION["username"];
$update="update employee set trn_date='".$trn_date."', empno='".$empno."',
empname='".$empname."', email='".$email."', phone='".$phone."',
depno='".$depno."', desig='".$desig."', salary='".$salary."',
submittedby='".$submittedby."' where id='".$id."'";
mysqli_query($con, $update) or die(mysqli_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View
Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
46
}
else
{
?>
<h1>Update Record</h1>
<div>
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
EMPLOYEE NO : <input type="text" name="empno" value="<?php echo
$row['empno'];?>" /></br>
EMPLOYEE NAME : <input type="text" name="empname" value="<?php
echo $row['empname'];?>" /></br>
DEPARTMENT NO : <input type="text" name="depno" value="<?php echo
$row['depno'];?>" /></br>
DESIGNATION : <input type="text"
name="desig" value="<?php echo $row['desig'];?>" /></br>
SALARY : <input type="text" name="salary"
value="<?php echo $row['salary'];?>" /></br>
EMAIL ID : <input type="email" name="mailid"
value="<?php echo $row['email'];?>" /></br>
PHONE NO. : <input type="text" name="phone" value="<?php echo
$row['phone'];?>" /></br>
<p><input name="submit" type="submit" value=" UPDATE " /></p>
</form>
<?php } ?>
</div>
</div>
</body>
</html>
47
DELETE.PHP:
<?php
require('db.php');
$id=$_REQUEST['id'];
$query = "DELETE FROM employee WHERE id=$id";
$result = mysqli_query($con,$query) or die ( mysqli_error());
header("Location: view.php");
?>
VIEW.PHP:
<?php
require('db.php');
include("auth.php");
?>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div style="text-align:center; margin-center:20px; margin-top:50px; margin-
bottom:5px ;font-size:10pt">
<h2> <a href="insert.php"> INSERT NEW </a> |
<a href="view.php"> VIEW RECORDS </a> |
<a href="logout.php"> LOGOUT </a></h2><br>
<h2>VIEW RECORDS</h2><br>
<table align="center" width="60%" border="2" style="border-collapse:collapse;">
<thead>
<tr>
48
<th><strong> S.NO </strong></th>
<th><strong> EMPLOYEE NO </strong></th>
<th><strong> EMPLOYEE NAME </strong></th>
<th><strong> DEPARTMENT NO </strong></th>
<th><strong> DESIGNATION </strong></th>
<th><strong> SALARY </strong></th>
<th><strong> EMAIL ADDRESS </strong></th>
<th><strong> PHONE NO </strong></th>
<th><strong> EDIT </strong></th>
<th><strong> DELETE </strong></th>
</tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select * from employee ORDER BY id asc;";
$result = mysqli_query($con,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr align="center">
<td><?php echo $count; ?></td>
<td><?php echo $row["empno"]; ?></td>
<td><?php echo $row["empname"]; ?></td>
<td><?php echo $row["depno"]; ?></td>
<td><?php echo $row["desig"]; ?></td>
<td><?php echo $row["salary"]; ?></td>
<td><?php echo $row["email"]; ?></td>
<td><?php echo $row["phone"]; ?></td>
<td><a href="edit.php?id=<?php echo $row["id"]; ?>">Edit</a></td>
<td><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a>
</td>
49
</tr>
<?php
$count++;
}
?>
</tbody>
</table>
</div>
</body>
</html>
LOGOUT.PHP:
<?php
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: login.php"); // Redirecting To Home Page
}
?>
50
OUTPUT:
PHPMYADMIN:
REGISTRATION:
51
LOGIN:
INSERT:
52
UPDATE:
VIEW:
53
DELETE:
54
RESULT:
Thus, the above program has been executed successfully and verified the output.
55