EMPLOYEE MANAGEMENT SYSTEM IN PHP WITH SOURCE CODE
employee mangement system developed using php , mysql ,jquery ,css ,html
installation code:-
<?php
$conn=mysqli_connect("localhost","root","","caroline");
$query="
CREATE TABLE `employee` (
`id` int(11) NOT NULL,
`name` varchar(250) NOT NULL,
`contact` varchar(250) NOT NULL,
`designation` varchar(250) NOT NULL,
`salary` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
";
$data=mysqli_query($conn,$query);
?>
index.php
<!DOCTYPE html>
<html>
<head>
<title>employee management</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="../caroline.css">
</head>
<body>
<style>
.insert-data{
position: absolute;
top:50%;
left:50%;
height: 550px;
}
.input{
padding: 2px;
}
.insert-data label{
font-size: 18px;
margin: 5px;
}
.edit-data{
position: absolute;
top:50%;
left:50%;
display: none;
}
.input-box{
margin: 10px;
}
.edit-data{
position: absolute;
top:40%;
left:50%;
height: 450px;
width: 400px;
background: #FFF;
display: none;
border:1px solid #CCc;
border-radius: 4px;
padding: 10px;
transform: translate(-50%,-50%);
//background: #4e89ae;
transition: 2s linear;
}
</style>
<div class="head">
<h1>employee management</h1>
</div>
<h1 class="he"></h1>
<div class="add-data">
<button id="add" class="btn btn-primary">Add data</button>
</div>
<div class="insert-data">
<button id="close" class=" btn btn-primary">close</button>
<form method="post">
<div class="input-box">
<label> name
</label><input type="text" name="name" class="input"id="name">
</div>
<div class="input-box">
<label>contact</label><input type="text" class="input" name="address" id="address">
</div>
<div class="input-box">
<label>designation</label><input type="text"class="input" name="address" id="desc">
</div>
<div class="input-box">
<label>salary</label><input type="text"class="input" name="address" id="salary">
</div>
<div class="input-box">
<input class="btn btn-primary "type="button"id="submit" value="submit">
</div>
</form>
</div>
<div class="edit-data">
<h1>update record</h1>
<form method="post">
<input type="hidden" id="empid">
<div class="input-box">
<label> name</label><br><input type="text"class="input" name="name" id="edit-name">
</div>
<div class="input-box">
<label>contact</label><br><input type="text"class="input" name="address" id="edit-address">
</div>
<div class="input-box">
<label>designation</label><br><input type="text" class="input"name="address" id="edit-desc">
</div>
<div class="input-box">
<label>salary</label><br><input type="text" class="input"name="address" id="edit-sal">
</div>
<div class="input-box">
<input class="btn btn-primary" type="button"id="update" value="update"><button id="close-edit" class="btn btn-danger">close</button>
</div>
</form>
</div>
<div class="table-data">
</div>
<script type="text/javascript">
$(document).ready(function()
{
$("#add").click(function()
{
//alert("asdf");
$(".insert-data").slideDown("slow");
//$('.insert-data').css("display","block");
});
$("#close").click(function()
{
//alert("asdf");
$('.insert-data').css("display","none");
});
$("#close-edit").click(function()
{
//alert("asdf");
$('.edit-data').css("display","none");
});
insert_record();
function insert_record()
{
$("#submit").on('click',function()
{
var action=$('.edit-btn').data('action');
var rollno=$('.edit-btn').data('rollno');
//alert(action);
//alert(rollno);
var name=$("#name").val();
var address=$("#address").val();
var desc=$("#desc").val();
var salary=$("#salary").val();
if(name=="")
{
//alert("empty");
}
else
{
$.ajax({
url:'action_data.php',
method:'post',
data:{name,name,address,address,desc,desc,salary,salary},
success:function(data)
{
load_data();
alert("successfully inserted")
$("#name").val(null);
$("#address").val(null);
$("#desc").val(null);
$("#salary").val(null);
}
})
}
})
}
load_data();
function load_data()
{
var action="load";
$.ajax({
url:'action_data.php',
method:'post',
data:{select:action},
success:function(data)
{
$('.insert-data').css("display","none");
$(".table-data").html(data);
//load_data();
}
});
}
$("#update").click(function()
{ var action="update_data";
var name=$("#edit-name").val();
var add=$("#edit-address").val();
var desc=$("#edit-desc").val();
var sal=$("#edit-sal").val();
var id=$("#empid").val();
$.ajax({
url:'action_data.php',
method:'post',
data:{update_data:action,name,name,id,id,add,add,desc,desc,sal,sal},
success:function(data)
{
$('.edit-data').css("display","none");
load_data();
}
});
});
});
function load_data()
{
var action="load";
$.ajax({
url:'action_data.php',
method:'post',
data:{select:action},
success:function(data)
{
$('.insert-data').css("display","none");
$(".table-data").html(data);
//load_data();
}
});
}
function delete_record(id)
{
//alert(id);
var action=$('.edit-btn').data('action');
var rollno=$('.edit-btn').data('rollno');
//alert(action);
var rollno=id;
var x=confirm("are you sure");
if(x)
{
//alert(rollno);
$.ajax({
url:'action_delete.php',
method:'post',
data:{rollno,rollno},
success:function(data)
{
load_data();
}
});
}
}
function edit_record(id)
{
var update="update";
var id =id;
// alert(id);
// var name=$('#edit').data('name');
// var contact=$('#edit').data('contact');
$("#edit-name").val(name);
$('.edit-data').css("display","block");
$.ajax({
url:'action_data.php',
method:'post',
data:{update:update,id,id},
success:function(data)
{
$array=$.parseJSON(data);
$("#empid").val($array.id);
$("#edit-name").val($array.name);
$("#edit-address").val($array.contact);
$("#edit-desc").val($array.desc);
$("#edit-sal").val($array.sal);
}
});
}
</script>
</body>
</html>
action_delete.php
<?php
$conn=mysqli_connect("localhost","root","","caroline");
echo $rollno=$_POST["rollno"];
$query="delete from employee where id=$rollno";
$data=mysqli_query($conn,$query);
?>
action_data.php
<?php
error_reporting(0);
$conn=mysqli_connect("localhost","root","","caroline");
if(isset($_POST["name"]))
{
$name=$_POST["name"];
$add=$_POST["address"];
$desc=$_POST["desc"];
$salary=$_POST["salary"];
$query="insert into employee(name,contact,designation,salary)values('$name','$add','$desc',$salary)";
$data=mysqli_query($conn,$query);
if($data)
{
echo"successfully";
}
}
if($_POST["select"]=='load')
{
echo"
<table class='table'>
<tr>
<th>emp no</th>
<th>Name</th>
<th>contact</th>
<th>designation</th>
<th>salary</th>
<th>Edit</th>
<th>Delete</th>
</tr>";
$query="select * from employee";
$data=mysqli_query($conn,$query);
while($res=mysqli_fetch_array($data))
{
$name=$res["name"];
$id=$res["id"];
echo"<tr>
<td>".$res["id"]."</td>
<td>".$res["name"]."</td>
<td>".$res["contact"]."</td>
<td>".$res["designation"]."</td>
<td>₹ ".$res["salary"]."</td>
<td><button class='btn btn-primary update' id='edit' onclick='edit_record(".$res[0].")' data-contact=".$res[2].">edit</button></td>
<td><button class='edit-btn btn btn-danger' onclick='delete_record(".$res[0].")'data-action='edit' data-rollno=".$res["id"].">delete</button></td>
</tr>";
}
/* */
}
if($_POST["update"]=='update')
{
$id=$_POST["id"];
$query="select * from employee where id=$id";
$data=mysqli_query($conn,$query);
$res=mysqli_fetch_array($data);
//print_r($res);
$name=$res["name"];
$id=$res["id"];
$contact=$res["contact"];
$desc=$res["designation"];
$sal=$res["salary"];
$emp_data=array('id'=>$id,'name'=>$name,'contact'=>$contact,'desc'=>$desc,'sal'=>$sal);
echo json_encode($emp_data);
}
if($_POST["update_data"]=='update_data')
{
$name=$_POST["name"];
$add=$_POST["add"];
$desc=$_POST["desc"];
$sal=$_POST["sal"];
$id=$_POST["id"];
$query="update employee set name='$name',contact='$add',designation='$desc',salary=$sal where id=$id";
$data=mysqli_query($conn,$query);
}
?>
Post a Comment
If you have any doubts, Please let me know
Thanks!