Current Location: Home> Latest Articles> Guide to Developing an Online Employee Attendance Card Replacement Module with PHP and Vue

Guide to Developing an Online Employee Attendance Card Replacement Module with PHP and Vue

M66 2025-10-10

Introduction

With the advancement of enterprise information technology, more companies are adopting online attendance systems to manage employee attendance. In practical scenarios, employees may need to request a card replacement for special reasons. This article explains how to develop an online employee attendance card replacement module using PHP and Vue, including detailed code examples.

Technology Selection

During development, PHP is used on the back end to handle server logic and database operations, while Vue is used on the front end to build interactive interfaces for form submission and data display.

Back-End Development

First, create a PHP file to handle the logic for card replacement requests, including database connection, data validation, and database operations.

// Connect to database
$conn = new mysqli("localhost", "username", "password", "database");

// Check database connection
if ($conn->connect_error) {
    die("Database connection failed: " . $conn->connect_error);
}

// Handle card replacement request logic
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve submitted form data
    $employee_id = $_POST["employee_id"];
    $date = $_POST["date"];
    $reason = $_POST["reason"];

    // SQL statement to insert card replacement request into database
    $sql = "INSERT INTO attendance (employee_id, date, reason) VALUES ('$employee_id', '$date', '$reason')";

    if ($conn->query($sql) === TRUE) {
        echo "Card replacement request successful";
    } else {
        echo "Card replacement request failed: " . $conn->error;
    }

    $conn->close();
}

Front-End Development

The front end uses Vue to implement the card replacement request form and interaction with the back end. Component-based development improves maintainability.

<form @submit="submitForm">
  <label for="employee_id">Employee ID:</label>
  <input type="text" id="employee_id" v-model="employeeId">
  <br>
  <label for="date">Date:</label>
  <input type="date" id="date" v-model="date">
  <br>
  <label for="reason">Reason:</label>
  <textarea id="reason" v-model="reason"></textarea>
  <br>
  <button type="submit">Submit</button>
</form>
export default {
  data() {
    return {
      employeeId: '',
      date: '',
      reason: ''
    }
  },
  methods: {
    submitForm() {
      // Send POST request to back end
      axios.post('api/apply.php', {
        employee_id: this.employeeId,
        date: this.date,
        reason: this.reason
      })
      .then(response => {
        console.log(response.data);
        // Handle card replacement result
      })
      .catch(error => {
        console.error(error);
      });
    }
  }
}

Conclusion

By following the above steps, we have successfully implemented an online employee attendance card replacement module using PHP and Vue. Employees can fill out the request form on a webpage and submit it to the back end for processing. This article provides a complete development approach and code examples to help developers quickly implement an automated internal attendance management system.