<?php
include('connect.php');  // ดึงการเชื่อมต่อเข้ามา

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $headline = $con->real_escape_string($_POST['headline']);
    $content  = $con->real_escape_string($_POST['content']);

    $sql = "INSERT INTO news (headline, content, time_news) 
            VALUES ('$headline', '$content', NOW())";

    if ($con->query($sql) === TRUE) {
        header("Location: ?page=news_student");
        exit();
    } else {
        echo "Error: " . $sql . "<br>" . $con->error;
    }
} else {
    echo "Invalid Request";
}
?>
