PHP Basic Project #1 for Absolute Beginners – Employee Management System

0
789
php_projects_for_beginners_1

Today we will try to build a simple Employee Management System for Absolute Beginners. I have tried to keep this project HELL SIMPLE. With Basic PHP-MySql Connectivity. In this project, I have not created Log-In/Sign-up System – I will create more advanced Projects soon and will teach them here too in future. For Today, let’s learn this simple project and get our hands dirty with basic Programming of PHP with MySqli.

php_projects_for_beginners_1php_projects_for_beginners_1

dbcon.php

<?php 
$host="localhost";
$username="root";
$password="";
$conn=mysqli_connect($host,$username,$password) or 
die("unable to create connection. ".mysqli_error($conn));

$qry="CREATE DATABASE IF NOT EXISTS employee";
$run=mysqli_query($conn,$qry) or die("Cannot create database");
mysqli_select_db($conn,"employee") or 
die("Cannot connect to database".mysqli_error($conn));

?>

index.php

<!DOCTYPE html>
<html lang="en_US">
 <head>
 <meta charset="utf-8">
 <title>Employee Management System</title> 
 </head>
 <body bgcolor="#f0f0f0">
 <h1>Hello There!</h1>
 <h2>Insert Records Below</h2>
 <table style="text-align:center">
 <form action="insert.php" method="post" name="frm1">
 <tr>
 <td>Name: </td>
 <td><input type="text" name="name" required></td>
 </tr>
 <tr>
 <td>Salary: </td>
 <td><input type="text" name="salary"></td>
 </tr>
 <tr>
 <td>Designation: </td>
 <td><input type="text" name="des"></td>
 </tr>
 <tr> 
 <td>ID: </td>
 <td><input type="text" name="id" ></td>
 </tr>
 <tr>
 <td colspan="2">
 <input type="submit" name="submit" value="Insert Data">
 </td>
 </tr>
 </form>
 </table>
 <h3>To Retrieve Records</h3>
 <a href="find.php">Click Here</a>
 </body>
</html>

insert.php

<?php
require_once("dbcon.php");

$qry="CREATE TABLE IF NOT EXISTS `emp`(
 `empid` int NOT NULL auto_increment, 
 `empname` varchar(20) NOT NULL,
 `salary` int, 
 `emp_des` text,
 PRIMARY KEY(`empid`)
)";
$run=mysqli_query($conn,$qry) or die("Cannot create table ".mysqli_error($conn));

$name=$_POST['name'];
$salary=$_POST['salary'];
$des=$_POST['des'];
$id=$_POST['id'];

$qry="INSERT INTO `emp` (`empname`,`empid`,`emp_des`,`salary`) 
VALUES('$name','$id','$des','$salary')";
$run=mysqli_query($conn,$qry) or 
die("Data Insertion Failed. ".mysqli_error($conn));

if($run)
 echo "Data Inserted Succeeded. Click Here to go Back.";
 echo "<html><body><a href='index.php'>Home</a></body></html>"

?>

find.php

<html>
 <head>
 <title>Search Employee</title>
 </head>
 <body>
 <h3>To Retrieve Records</h3>
 <form action="find.php" method="get" name="frm2">
 <input type="text" name="des" placeholder="Enter Designation : ">
 <!--<button type="submit" name="find">Find Data</button>-->
 <input type="submit" name="submit">
 </form>
 </body>
</html>
<?php


if(isset($_GET['submit'])){
 require_once("dbcon.php");
 $des=$_GET['des'];
 $qry= "SELECT * FROM `emp` WHERE emp_des='$des' ";
 $result=mysqli_query($conn,$qry) ;
 $n=mysqli_num_rows($result);
 
 if($n<1){
 echo "No Records Found"; 
 }
 else{
 echo "<table border=1>";
 echo "<th>Name</th> <th>Salary</th>";
 while($row = mysqli_fetch_assoc($result))
 { 
 echo "<tr><td>".$row['empname'] . "</td>" ; 
 echo "<td>". $row['salary']."</td></tr>" ;

}
 echo "</table>";
 }
 
 echo "<br>Click Here to go Back.";
 echo "<html><body><a href='index.php'>Home</a></body></html>"; 
 
 
 }
?>

 

 

For More Projects on PHP and Programming Lessons, do subscribe to our newsletter to receive all the notifications. To Download Above Project in a folder, download it here from Google Drive (Database File is inside the folder itself with .sql extension).

LEAVE A REPLY

Please enter your comment!
Please enter your name here