Current Location: Home> Latest Articles> Complete Guide to Tracking Employee Attendance Approval with PHP

Complete Guide to Tracking Employee Attendance Approval with PHP

M66 2025-11-05

How to Track Employee Attendance Approval with PHP

As companies place more emphasis on employee attendance management, electronic attendance systems have become increasingly common. To conveniently track and approve employee attendance records, PHP, a popular server-side scripting language, is widely used in developing these systems. This article explains how to implement employee attendance approval tracking with PHP and provides practical code examples.

Database Design

First, we need to design a database to store employee attendance information. Here is a simple database table example:

CREATE TABLE `attendance` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `employee_id` INT(11) NOT NULL,
  `date` DATE NOT NULL,
  `status` ENUM('Pending', 'Approved', 'Rejected') NOT NULL DEFAULT 'Pending',
  PRIMARY KEY (`id`)
);

In this table, attendance stores each employee's attendance record. id is the primary key for unique identification, employee_id stores the employee ID, date records the attendance date, and status indicates the approval status, including Pending, Approved, and Rejected.

PHP Implementation

Connecting to the Database

Use PHP to connect to the database. Example:

<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";

// Create database connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Database connection failed: " . $conn->connect_error);
}
?>

Replace your_username, your_password, and your_database with your actual database credentials.

Querying Attendance Records

Write PHP code to query and display employee attendance records:

<?php
// Query attendance records
$sql = "SELECT * FROM attendance";
$result = $conn->query($sql);

// Check if records exist
if ($result->num_rows > 0) {
    // Output data
    while($row = $result->fetch_assoc()) {
        echo "Employee ID: " . $row["employee_id"] . " - Date: " . $row["date"] . " - Status: " . $row["status"] . "<br>";
    }
} else {
    echo "No attendance records found";
}
?>

Updating Attendance Records

When approving attendance records, update the record's approval status:

<?php
// Update attendance approval status
$attendance_id = 1;  // ID of the record to update
$status = "Approved";  // New approval status

$sql = "UPDATE attendance SET status='$status' WHERE id=$attendance_id";

if ($conn->query($sql) === TRUE) {
    echo "Attendance record updated successfully";
} else {
    echo "Failed to update attendance record: " . $conn->error;
}
?>

This example updates the attendance record with ID 1 to 'Approved'. Adjust $attendance_id and $status according to your needs.

Conclusion

With the PHP code above, companies can track employee attendance approval effectively. Using database storage and PHP operations, you can query and update attendance records and display approval results. This example demonstrates a basic implementation; a complete attendance management system may require additional features to meet enterprise needs. We hope this guide helps you build your PHP attendance system successfully.