0% found this document useful (0 votes)
18 views3 pages

HRMS Source Code

The document provides the complete source code for a Human Resource Management System (HRMS) using MySQL for the database. It includes functionalities for user login, adding and viewing employees, and a dashboard interface. The code covers database creation, connection, and essential PHP scripts for managing user sessions and employee records.

Uploaded by

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

HRMS Source Code

The document provides the complete source code for a Human Resource Management System (HRMS) using MySQL for the database. It includes functionalities for user login, adding and viewing employees, and a dashboard interface. The code covers database creation, connection, and essential PHP scripts for managing user sessions and employee records.

Uploaded by

solomonbaye10909
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Human Resource Management System

(HRMS) - Complete Source Code


1. Database (MySQL)
CREATE DATABASE hrms;
USE hrms;

CREATE TABLE employees (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
phone VARCHAR(20),
position VARCHAR(50),
salary DECIMAL(10,2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE users (


id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50),
password VARCHAR(255)
);

2. Database Connection ([Link])


<?php
$conn = new mysqli("localhost", "root", "", "hrms");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

3. Login System ([Link])


<?php
session_start();
include '[Link]';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT * FROM users WHERE username='$username' AND


password='$password'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
$_SESSION['user'] = $username;
header("Location: [Link]");
} else {
echo "Invalid login!";
}
}
?>

4. Dashboard ([Link])
<?php
session_start();
if (!isset($_SESSION['user'])) {
header("Location: [Link]");
}
?>

<h2>Welcome to HRMS Dashboard</h2>


<a href="add_employee.php">Add Employee</a> |
<a href="view_employee.php">View Employees</a> |
<a href="[Link]">Logout</a>

5. Add Employee (add_employee.php)


<?php
include '[Link]';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$position = $_POST['position'];
$salary = $_POST['salary'];

$sql = "INSERT INTO employees (name,email,phone,position,salary)


VALUES ('$name','$email','$phone','$position','$salary')";
if ($conn->query($sql) === TRUE) {
echo "Employee added successfully!";
} else {
echo "Error: " . $conn->error;
}
}
?>

6. View Employees (view_employee.php)


<?php
include '[Link]';
$result = $conn->query("SELECT * FROM employees");
?>

<h2>Employee List</h2>
<table border="1">
<tr>
<th>ID</th><th>Name</th><th>Email</th><th>Phone</th><th>Position</
th><th>Salary</th>
</tr>
<?php while($row = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['position']; ?></td>
<td><?php echo $row['salary']; ?></td>
</tr>
<?php } ?>
</table>

7. Logout ([Link])
<?php
session_start();
session_destroy();
header("Location: [Link]");
?>

You might also like