Home  >  Article  >  Backend Development  >  How to implement employee attendance report management in PHP?

How to implement employee attendance report management in PHP?

WBOY
WBOYOriginal
2023-09-24 19:25:061077browse

How to implement employee attendance report management in PHP?

How to implement employee attendance report management in PHP?

In a company or organization, attendance report management is a very important task. It helps managers understand employee attendance and evaluate employee performance. In this article, we will introduce how to use PHP to implement an employee attendance report management system and provide some specific code examples.

  1. Create database and table
    First, we need to create a database in MySQL or other database management system. Then, create an employee table in the database to store employee information and attendance records. The form should contain fields such as employee ID, name, position, check-in time, etc. The following is an example SQL statement to create an employees table:

CREATE TABLE employees (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL ,
position VARCHAR(30) NOT NULL,
check_in_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

  1. Write PHP code to implement employee attendance report management
    Next, we will use Write code in PHP to implement employee attendance report management. First, we need to connect to the database and perform database query operations. The following is a sample PHP code for connecting to the database and performing query operations:

// Set database connection information
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_dbname";

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

// Check whether the connection is successful
if ($conn->connect_error) {

die("连接失败: " . $conn->connect_error);

}

// Query employee attendance records
$sql = "SELECT id, name, position, check_in_time FROM employees";
$result = $conn->query($sql);

// Check whether the query result is empty
if ($result->num_rows > 0) {

// 循环输出员工考勤记录
while($row = $result -> fetch_assoc()) {
    echo "员工ID:" . $row["id"]. ",姓名:" . $row["name"]. ",职位:" . $row["position"]. ",签到时间:" . $row["check_in_time"]. "<br>";
}

} else {

echo "员工考勤记录为空";

}

//Close the database connection
$conn->close();
?>

The above PHP code can obtain all records in the employee table and output the records to the web page.

  1. Front-end page design
    In order to better manage employee attendance reports, we can also create a front-end page to provide employee sign-in functions and display of employee attendance records. Here is an example HTML code that achieves this functionality:


<title>员工考勤报道</title>


<h1>员工考勤报道</h1>

<form action="check_in.php" method="post">
    <label for="name">姓名:</label>
    <input type="text" name="name" required><br>
    <label for="position">职位:</label>
    <input type="text" name="position" required><br>
    <input type="submit" value="签到">
</form>

<h2>员工考勤记录</h2>

<?php
// 显示员工考勤记录的PHP代码
// ...
?>


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

Statement:
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