<?php
include('../connection.php');
header("Content-Type: application/json");
mysqli_set_charset($conn, 'utf8mb4');
if (isset($_POST['id'])) {
    // Retrieve POST data
    $id = $_POST['id'];
    $check_count = $_POST['check_count'];  // New field
    $check_time = $_POST['check_time'];  // New field

    // Use prepared statements to prevent SQL injection
    $stmt = $conn->prepare("UPDATE ticket SET check_count=?, check_time=? WHERE id=?");
    $stmt->bind_param("ssi", $check_count, $check_time, $id);

    if ($stmt->execute()) {
        $response = [
            'status' => 'success',
            'message' => 'Data updated successfully',
        ];
    } else {
        $response = [
            'status' => 'error',
            'message' => 'Database error: ' . $stmt->error,
        ];
    }
    // Close the statement
    $stmt->close();
} else {
    $response = [
        'status' => 'error',
        'message' => 'No data found',
    ];
}

// Return JSON response
echo json_encode($response);

// Close the database connection
$conn->close();
?>
