<?php
session_start();
if(!isset($_SESSION['admin'])){
    header("Location: login.php");
}
include("../config/db.php");

if(isset($_POST['save'])){
    $title = $_POST['title'];
    $content = $_POST['content'];

    $conn->query("INSERT INTO news(title,content) VALUES('$title','$content')");
    $success = "บันทึกข่าวเรียบร้อยแล้ว";
}
?>

<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="utf-8">
<title>เพิ่มข่าว</title>
<link rel="stylesheet" href="../css/style.css">
</head>
<body>

<div class="container">
<h2 class="page-title">เพิ่มข่าวประชาสัมพันธ์</h2>

<div class="content-box">

<?php if(isset($success)) echo "<p style='color:green'>$success</p>"; ?>

<form method="post">
<input type="text" name="title" placeholder="หัวข้อข่าว" required><br><br>
<textarea name="content" placeholder="รายละเอียดข่าว" rows="6" required></textarea><br><br>
<button name="save">บันทึกข่าว</button>
</form>

<br>
<a href="dashboard.php">← กลับหน้าหลังบ้าน</a>

</div>
</div>

</body>
</html>
