Home > Article > Backend Development > How to use PHP and Vue to develop a check-in reminder function for online employee attendance
How to use PHP and Vue to develop online employee attendance check-in reminder function
With the development of technology, many companies have begun to adopt online employee attendance systems to better Manage employee working hours and attendance. One of the important functions is the sign-in reminder, which enables employees to sign in in a timely manner and ensures accurate recording of working hours. This article will introduce how to use PHP and Vue to develop the check-in reminder function for online employee attendance, and provide specific code examples.
<?php // 连接数据库 $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; $conn = new mysqli($servername, $username, $password, $dbname); // 获取员工信息 $employeeId = $_POST["employee_id"]; $signInTime = date("Y-m-d H:i:s"); // 将签到信息插入数据库 $sql = "INSERT INTO attendance (employee_id, sign_in_time) VALUES ('$employeeId', '$signInTime')"; if ($conn->query($sql) === TRUE) { echo "签到成功"; } else { echo "签到失败"; } $conn->close(); ?>
In the above code, we first connect to the database and then get the employee ID and current time. Next, we insert this information into a table named attendance
, which contains two fields: employee ID and check-in time. According to the operation result, the corresponding prompt information is output.
<template> <div> <p v-if="!isSignedIn">请在指定时间段内完成签到</p> <button v-if="!isSignedIn" @click="signIn">签到</button> <p v-else>已完成签到</p> </div> </template> <script> export default { data() { return { isSignedIn: false }; }, methods: { signIn() { // 发送签到请求 axios.post("/api/signin", { employee_id: 123 // 员工ID }) .then(response => { if (response.data === '签到成功') { this.isSignedIn = true; } }) .catch(error => { console.error(error); }); } } }; </script>
In the above code, we first define a isSignedIn
variable to indicate whether the sign-in has been completed. Based on the value of this variable, we can control the display of corresponding prompt information and sign-in buttons. When the user clicks the sign-in button, a POST request will be sent to the /api/signin
route on the backend and the employee ID will be passed. Based on the results returned by the backend, we update the value of the isSignedIn
variable to display the corresponding prompt information.
The above is the detailed content of How to use PHP and Vue to develop a check-in reminder function for online employee attendance. For more information, please follow other related articles on the PHP Chinese website!