
        <?php include 'include/navbar.php';?>
        <?php include 'include/sidebar.php';?>
     
            <div id="layoutSidenav_content">
                <main>
                    <div class="container-fluid px-4">
                        <h1 class="mt-4">Dashboard</h1>
                        <ol class="breadcrumb mb-4">
                            <li class="breadcrumb-item active">Add Blog</li>
                        </ol>

                        <div class=" mt-4">

                            <?php

if (isset($_POST['submit'])) {
    
$imageName = $_FILES['image']['name'];
$imageTmp = $_FILES['image']['tmp_name'];
$imagePath = "../uploads/" . $imageName;

move_uploaded_file($imageTmp, $imagePath);

// Sanitize inputs
$title = $conn->real_escape_string($_POST['title']);
$date = date('M d, Y'); 
$shortDesc = $conn->real_escape_string($_POST['short_description']);
$longDesc = $conn->real_escape_string($_POST['long_description']);

// Insert into DB
$sql = "INSERT INTO blogs (title, date, image, short_description, long_description)
        VALUES ('$title', '$date', '$imagePath', '$shortDesc', '$longDesc')";

if ($conn->query($sql) === TRUE) {
    echo "<p class='p-2 bg-success text-white rounded  text-center'>Blog added successfully!";
} else {
    echo "Error: " . $conn->error;
}
}
?>

<form action="" method="POST" enctype="multipart/form-data">
  <label>Blog Title:</label>
  <input type="text" class="form-control" name="title" required><br><br>

  <label>Image:</label>
  <input type="file" class="form-control" name="image" accept="image/*" required><br><br>

  <label>Short Description:</label>
  <textarea name="short_description" class="form-control" rows="3" required></textarea><br><br>

  <label>Long Description:</label>
  <textarea name="long_description" class="form-control" rows="6"  id="arContent" required></textarea><br><br>

  <button type="submit" name="submit" class="btn btn-primary">Add Blog</button>
</form>

                    </div>
                </main>
                <?php include "include/footer.php";?>
            </div>
        </div>
<!-- JS TextEditor -->
<script src="//cdn.ckeditor.com/4.13.1/standard/ckeditor.js"></script>
         <script>
        CKEDITOR.replace('arContent');
    </script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
        <script src="js/scripts.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
        <script src="assets/demo/chart-area-demo.js"></script>
        <script src="assets/demo/chart-bar-demo.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" crossorigin="anonymous"></script>
        <script src="js/datatables-simple-demo.js"></script>
    </body>
</html>
