    <?php
    session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: index.php');
    exit;
}
require 'dbconn.php';

// Sanitize and retrieve form data
$title = trim($_POST['news_title']);
$date = $_POST['news_date'];
$description = trim($_POST['desc']);

// Prepare insert query
$query = "INSERT INTO circulars_tb (circular_title, circular_date, description) VALUES (?, ?, ?)";
$stmt = $mysqli->prepare($query);

if (!$stmt) {
    die("Prepare failed: " . $mysqli->error);
}

$stmt->bind_param("sss", $title, $date, $description);

// Execute and handle result
if ($stmt->execute()) {
    // Redirect on success
    header("Location: manage_circulars.php?success=1");
    exit;
} else {
    echo "Error inserting circular: " . $stmt->error;
}

$stmt->close();
$mysqli->close();
?>
