<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo "Access Denied";
    exit();
}

include 'config.php';

foreach(array('headline', 'id') as $field) {
    if(!isset($_POST[$field]) || trim($_POST[$field]) == '') {
        echo $field." is required";
        exit();
    }
}

$sql = "UPDATE notice SET headline = ? WHERE id = ?";

$stmt = $conn->prepare($sql);
if ($stmt) {
    $stmt->bind_param("ss", $_POST['headline'], $_POST['id']);

    if ($stmt->execute()) {
        echo "Notice Send Successful";
    } else {
        echo "Notice Send Failed";
    }
    $stmt->close();
} else {
    echo "Notice Send Failed";
}
$conn->close();
?>