<?php
require 'db_config.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $attendance_id = intval($_POST['attendance_id']);
    $promotional_materials = isset($_POST['promotional_material']) ? implode(',', $_POST['promotional_material']) : '';

    // Update the promotional materials for the specified attendance record
    $stmt = $conn->prepare("UPDATE attendance SET promotion_material = ? WHERE id = ?");
    $stmt->bind_param("si", $promotional_materials, $attendance_id);

    if ($stmt->execute()) {
        echo "Promotional material updated successfully!";
    } else {
        echo "Error: " . $stmt->error;
    }

    $stmt->close();
}

$conn->close();

// Redirect back to the attendance page
header("Location: attendance.php");
exit();
?>
