以下是一个简单的员工打卡系统的示例代码:
index.php:
<!DOCTYPE html>
<html>
<head>
<title>员工打卡系统</title>
</head>
<body>
<h1>员工打卡系统</h1>
<form action="process.php" method="post">
<label for="employee_id">员工ID:</label>
<input type="text" name="employee_id" id="employee_id" required>
<button type="submit">签到</button>
</form>
</body>
</html>
process.php:
<?php
// 连接数据库
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "employee_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("数据库连接失败: " . $conn->connect_error);
}
// 获取员工ID
$employee_id = $_POST['employee_id'];
// 获取当前日期和时间
$date = date('Y-m-d');
$time = date('H:i:s');
// 检查员工是否已经签到过
$sql = "SELECT * FROM attendance WHERE employee_id = '$employee_id' AND date = '$date'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "员工已经签到过";
} else {
// 插入签到记录
$sql = "INSERT INTO attendance (employee_id, date, time) VALUES ('$employee_id', '$date', '$time')";
if ($conn->query($sql) === TRUE) {
echo "签到成功";
} else {
echo "签到失败: " . $conn->error;
}
}
$conn->close();
?>
注意:这只是一个简单的示例,实际的员工打卡系统可能需要更多的功能和验证。此外,建议将数据库连接信息存储在一个单独的配置文件中,以提高安全性。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站