Home Backend Development PHP Tutorial How to implement employee leave management function through PHP?

How to implement employee leave management function through PHP?

Sep 26, 2023 pm 06:04 PM
staff manage Ask for leave

How to implement employee leave management function through PHP?

How to implement employee leave management function through PHP?

Employee leave management is an important function in an enterprise. Effectively managing employees' leave applications can improve the company's work efficiency and employees' work enthusiasm. As a popular server-side scripting language, PHP is loved by developers because of its ease of learning, ease of use and flexibility. Through PHP, we can quickly implement employee leave management functions.

The following will introduce how to write an employee leave management system through PHP and provide specific code examples.

  1. Database design

First, we need to design a database to store employees' leave information. Create a database named "leave_management" and create a table named "leave_requests" in it. The table should contain the following fields:

  • id (auto-increment primary key)
  • employee_name (employee name)
  • leave_type (leave type)
  • leave_start_date (leave start date)
  • leave_end_date (leave end date)
  • leave_reason (leave reason)
  • status (leave status, such as pending approval, approved, rejected )
  1. Create a leave application form

Create a leave application form on the web page to collect employees' leave information. The following is a simple example:

<form method="post" action="process_leave.php">
  <label for="employee_name">员工姓名:</label>
  <input type="text" name="employee_name" id="employee_name" required>
  
  <label for="leave_type">请假类型:</label>
  <select name="leave_type" id="leave_type" required>
    <option value="病假">病假</option>
    <option value="事假">事假</option>
    <option value="年假">年假</option>
  </select>
  
  <label for="leave_start_date">请假开始日期:</label>
  <input type="date" name="leave_start_date" id="leave_start_date" required>
  
  <label for="leave_end_date">请假结束日期:</label>
  <input type="date" name="leave_end_date" id="leave_end_date" required>
  
  <label for="leave_reason">请假原因:</label>
  <textarea name="leave_reason" id="leave_reason" required></textarea>
  
  <input type="submit" value="提交申请">
</form>
Copy after login
  1. Processing leave requests

Next, we create a file called "process_leave.php" for processing employee requests Leave application. In this file we will get the various fields from the form and insert them into the database.

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

// 检查连接是否成功
if (!$conn) {
  die("数据库连接失败: " . mysqli_connect_error());
}

// 获取表单中的字段值
$employee_name = $_POST['employee_name'];
$leave_type = $_POST['leave_type'];
$leave_start_date = $_POST['leave_start_date'];
$leave_end_date = $_POST['leave_end_date'];
$leave_reason = $_POST['leave_reason'];

// 编写SQL语句并执行插入操作
$sql = "INSERT INTO leave_requests (employee_name, leave_type, leave_start_date, leave_end_date, leave_reason, status) 
        VALUES ('$employee_name', '$leave_type', '$leave_start_date', '$leave_end_date', '$leave_reason', '待审批')";

if (mysqli_query($conn, $sql)) {
  echo "请假申请提交成功";
} else {
  echo "请假申请提交失败: " . mysqli_error($conn);
}

// 关闭数据库连接
mysqli_close($conn);
?>
Copy after login
  1. Display leave information

In the web page, we can create a page to display employee leave information. The following is a simple example:

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

// 检查连接是否成功
if (!$conn) {
  die("数据库连接失败: " . mysqli_connect_error());
}

// 查询请假信息
$sql = "SELECT * FROM leave_requests";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
  while ($row = mysqli_fetch_assoc($result)) {
    echo "员工姓名: " . $row['employee_name'] . "<br>";
    echo "请假类型: " . $row['leave_type'] . "<br>";
    echo "请假开始日期: " . $row['leave_start_date'] . "<br>";
    echo "请假结束日期: " . $row['leave_end_date'] . "<br>";
    echo "请假原因: " . $row['leave_reason'] . "<br>";
    echo "请假状态: " . $row['status'] . "<br><br>";
  }
} else {
  echo "暂无请假申请";
}

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

Through the above steps, we can implement a basic employee leave management function through PHP. When an employee submits a leave application, his or her leave information will be inserted into the database and can be viewed through another page.

Of course, we can expand and improve this basic system according to actual needs, such as adding approval functions, employee login restrictions, etc. I hope the code examples in this article can help you better understand how to implement employee leave management functions through PHP.

The above is the detailed content of How to implement employee leave management function through PHP?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Redis to implement distributed transaction management How to use Redis to implement distributed transaction management Nov 07, 2023 pm 12:07 PM

How to use Redis to implement distributed transaction management Introduction: With the rapid development of the Internet, the use of distributed systems is becoming more and more widespread. In distributed systems, transaction management is an important challenge. Traditional transaction management methods are difficult to implement in distributed systems and are inefficient. Using the characteristics of Redis, we can easily implement distributed transaction management and improve the performance and reliability of the system. 1. Introduction to Redis Redis is a memory-based data storage system with efficient read and write performance and rich data

How to implement student performance management function in Java? How to implement student performance management function in Java? Nov 04, 2023 pm 12:00 PM

How to implement student performance management function in Java? In the modern education system, student performance management is a very important task. By managing student performance, schools can better monitor students' learning progress, understand their weaknesses and strengths, and make more targeted teaching plans based on this information. In this article, we will discuss how to use Java programming language to implement student performance management functions. First, we need to determine the data structure of student grades. Typically, student grades can be represented as a

Laravel extension package management: easily integrate third-party code and functions Laravel extension package management: easily integrate third-party code and functions Aug 25, 2023 pm 04:07 PM

Laravel extension package management: Easily integrate third-party code and functions Introduction: In Laravel development, we often use third-party code and functions to improve the efficiency and stability of the project. The Laravel extension package management system allows us to easily integrate these third-party codes and functions, making our development work more convenient and efficient. This article will introduce the basic concepts and usage of Laravel extension package management, and use some practical code examples to help readers better understand and apply it. What is Lara

Nintendo's new employee retention rate is 98.8%, and the average annual salary last year was 9.88 million yen Nintendo's new employee retention rate is 98.8%, and the average annual salary last year was 9.88 million yen Sep 14, 2023 am 08:49 AM

According to news from this site on September 2, Nintendo’s official website disclosed employee data. The new employee retention rate (the proportion of fresh graduates who joined the company in April 2019 and continued to work in the company in April 2022) is as high as 98.8%, of which 100% are male and 100% female. 96%. This means that for every 100 new employees Nintendo hires, about one decides to quit, while Japan's average new employee retention rate is 70%. Keitake Okamoto, CEO of UZUZ Co., Ltd., said: "Large companies usually provide high salaries and good benefits, so employee retention rates are higher, especially Nintendo as a popular representative company in Japan." "Last year, Nintendo's average The annual salary is 9.88 million yen (approximately 492,000 yuan), although there are some companies in the game industry with higher annual salaries than Nintendo.

What to do if the right-click menu management cannot be opened in Windows 10 What to do if the right-click menu management cannot be opened in Windows 10 Jan 04, 2024 pm 07:07 PM

When we use the win10 system, when we use the mouse to right-click the desktop or the right-click menu, we find that the menu cannot be opened and we cannot use the computer normally. At this time, we need to restore the system to solve the problem. Win10 right-click menu management cannot be opened: 1. First open our control panel, and then click. 2. Then click under Security and Maintenance. 3. Click on the right to restore the system. 4. If it still cannot be used, check whether there is something wrong with the mouse itself. 5. If you are sure there is no problem with the mouse, press + and enter. 6. After the execution is completed, restart the computer.

How to use the Hyperf framework for cache management How to use the Hyperf framework for cache management Oct 21, 2023 am 08:36 AM

How to use the Hyperf framework for cache management Cache is one of the important means to improve application performance, and modern frameworks provide us with more convenient cache management tools. This article will introduce how to use the Hyperf framework for cache management and provide specific code examples. The Hyperf framework is a high-performance framework developed based on Swoole. It has a rich set of built-in components and tools, including powerful cache management functions. The Hyperf framework supports multiple cache drivers, such as Redis and Memcach.

Analysis of solutions to transaction management problems encountered in MongoDB technology development Analysis of solutions to transaction management problems encountered in MongoDB technology development Oct 08, 2023 am 08:15 AM

Analysis of solutions to transaction management problems encountered in MongoDB technology development As modern applications become more and more complex and large, the transaction processing requirements for data are also getting higher and higher. As a popular NoSQL database, MongoDB has excellent performance and scalability in data management. However, MongoDB is relatively weak in data consistency and transaction management, posing challenges to developers. In this article, we will explore the transaction management issues encountered in MongoDB development and propose some solutions.

DNF mobile game has been released! Players are making fun of what 'can't wait' means DNF mobile game has been released! Players are making fun of what 'can't wait' means Apr 22, 2024 pm 05:30 PM

The DNF mobile game was officially announced today and will be officially launched on May 21. After the news was released, players started making jokes one after another, and various bizarre operations emerged one after another, just to pray for the smooth launch of the game. For example, some netizens have already asked for leave early, just so that they can return to the Arad continent as soon as possible. Some also took out the wooden fish that accumulated merit, praying that the DNF mobile game would be launched smoothly and that the ticket would not be delayed again. Even the old almanac has been magically modified to be suitable for "asking for leave" and "fighting DNF". It seems that since the last ticket bounced, the players have been frustrated for so many years. So the question is, will you take leave on May 21st for the DNF mobile game?

See all articles