Using PHP to develop an enterprise resource planning (ERP) system that implements employee attendance functions

王林
Release: 2023-07-01 21:10:02
Original
1366 people have browsed it

Use PHP to develop an enterprise resource planning (ERP) system that implements employee attendance functions

Introduction:
As the scale of enterprises gradually expands, human resource management becomes more and more important. In human resources management, employee attendance is a crucial link. In order to improve efficiency and reduce errors, many companies have begun to adopt enterprise resource planning (ERP) systems to manage employee attendance. This article will introduce how to use PHP to develop an enterprise resource planning (ERP) system that implements employee attendance functions, and provide relevant code examples.

1. Environment setup
Before starting, you first need to set up a PHP development environment. You can use integrated tools such as XAMPP, WAMP or LAMP, or you can choose to install components such as Apache, PHP and MySQL separately. Make sure the PHP version is 5.6 and above, and the MySQL database is installed.

2. Database design
First, you need to design a database to store employee attendance information. Create a database named "attendance" in MySQL and create a table named "employees", containing the following fields:

  • id: auto-increment primary key
  • name: Employee name
  • date: attendance date
  • in_time: clock-in time at work
  • out_time: clock-in time at work
  • status: attendance status (normal, late, early departure etc.)

You can use the following SQL statement to create this table:

CREATE TABLE `employees` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `date` date NOT NULL,
  `in_time` time NOT NULL,
  `out_time` time NOT NULL,
  `status` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
);
Copy after login

3. Create a web interface
Next, we need to create a web interface to display employee attendance information, And provides the function of entering attendance information. Create a file named "index.php" and add the following code:

<!DOCTYPE html>
<html>
<head>
    <title>员工考勤管理系统</title>
</head>
<body>
    <h1>员工考勤管理系统</h1>
    
    <?php
    // 连接MySQL数据库
    $conn = mysqli_connect("localhost", "root", "", "attendance");
    
    // 查询所有员工的考勤记录
    $sql = "SELECT * FROM employees";
    $result = mysqli_query($conn, $sql);
    
    // 显示员工考勤信息
    if (mysqli_num_rows($result) > 0) {
        echo "<table>";
        echo "<tr>";
        echo "<th>员工姓名</th>";
        echo "<th>考勤日期</th>";
        echo "<th>上班打卡时间</th>";
        echo "<th>下班打卡时间</th>";
        echo "<th>考勤状态</th>";
        echo "</tr>";
        
        while ($row = mysqli_fetch_assoc($result)) {
            echo "<tr>";
            echo "<td>" . $row["name"] . "</td>";
            echo "<td>" . $row["date"] . "</td>";
            echo "<td>" . $row["in_time"] . "</td>";
            echo "<td>" . $row["out_time"] . "</td>";
            echo "<td>" . $row["status"] . "</td>";
            echo "</tr>";
        }
        
        echo "</table>";
    } else {
        echo "暂无考勤记录";
    }
    
    // 关闭数据库连接
    mysqli_close($conn);
    ?>

    <h2>录入考勤信息</h2>
    <form action="add.php" method="post">
        <label for="name">员工姓名:</label>
        <input type="text" id="name" name="name" required><br>
        
        <label for="date">考勤日期:</label>
        <input type="date" id="date" name="date" required><br>
        
        <label for="in_time">上班打卡时间:</label>
        <input type="time" id="in_time" name="in_time" required><br>
        
        <label for="out_time">下班打卡时间:</label>
        <input type="time" id="out_time" name="out_time" required><br>
        
        <label for="status">考勤状态:</label>
        <input type="text" id="status" name="status" required><br>
        
        <input type="submit" value="提交">
    </form>
</body>
</html>
Copy after login

4. Add attendance information
Create a file named "add.php" and add the following code:

<?php
// 连接MySQL数据库
$conn = mysqli_connect("localhost", "root", "", "attendance");

// 获取表单数据
$name = $_POST["name"];
$date = $_POST["date"];
$in_time = $_POST["in_time"];
$out_time = $_POST["out_time"];
$status = $_POST["status"];

// 添加考勤记录到数据库
$sql = "INSERT INTO employees (name, date, in_time, out_time, status) VALUES ('$name', '$date', '$in_time', '$out_time', '$status')";

if (mysqli_query($conn, $sql)) {
    echo "成功添加考勤记录";
} else {
    echo "添加考勤记录失败:" . mysqli_error($conn);
}

// 关闭数据库连接
mysqli_close($conn);
?>
Copy after login

Run the "index.php" file to see the employee's attendance information, and add new attendance records through the form for entering attendance information.

Conclusion:
In this article, we use PHP to develop an enterprise resource planning (ERP) system that implements employee attendance functions. By creating a database, designing a web interface, and using PHP code to query and add data, we successfully implemented a simple employee attendance management system. Enterprises can expand and optimize functions according to actual needs to adapt to different human resource management needs.

The above is the detailed content of Using PHP to develop an enterprise resource planning (ERP) system that implements employee attendance functions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!