PHP排班考勤打卡系统可以用于管理员工的考勤记录和排班安排。以下是一个简单的PHP代码示例,用于实现基本的考勤打卡功能:
CREATE TABLE attendance (
id INT AUTO_INCREMENT PRIMARY KEY,
employee_id INT,
date DATE,
clock_in_time TIME,
clock_out_time TIME
);
<?php
// 连接数据库
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查数据库连接是否成功
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// 处理考勤打卡请求
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$employee_id = $_POST["employee_id"];
$clock_in_time = date("H:i:s");
// 检查员工是否已经打过卡
$sql = "SELECT * FROM attendance WHERE employee_id = '$employee_id' AND date = CURDATE()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 员工已经打过卡,更新打卡时间
$sql = "UPDATE attendance SET clock_out_time = '$clock_in_time' WHERE employee_id = '$employee_id' AND date = CURDATE()";
$conn->query($sql);
echo "Clock out success!";
} else {
// 员工还未打卡,插入新的考勤记录
$sql = "INSERT INTO attendance (employee_id, date, clock_in_time) VALUES ('$employee_id', CURDATE(), '$clock_in_time')";
$conn->query($sql);
echo "Clock in success!";
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Attendance System</title>
</head>
<body>
<h1>Attendance System</h1>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
Employee ID: <input type="text" name="employee_id">
<input type="submit" value="Clock In/Out">
</form>
</body>
</html>
通过访问"index.php"页面,你可以输入员工ID并进行考勤打卡操作。系统会根据员工是否已经打过卡来更新考勤记录。
下一篇:php人员信息管理模板
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站