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.
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
);
// 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.
<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!