
PK 
<?php
include('../includes/auth.php');
include('../../includes/db.php');
include('../includes/header.php');
include('../includes/sidebar.php');
if(isset($_POST['submit'])){
$title = $_POST['title'];
$content = $_POST['content'];
$short = $_POST['short_description'];
$category = !empty($_POST['category_id']) ? $_POST['category_id'] : "NULL";
$read_time = $_POST['read_time'];
$uploadDir = "../../uploads/";
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$image = $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];
move_uploaded_file($tmp, $uploadDir . $image);
$query = "INSERT INTO blogs(title, content, short_description, category_id, read_time, image)
VALUES('$title','$content','$short',$category,'$read_time','$image')";
mysqli_query($conn, $query);
header("Location: index.php");
}
?>
<div class="top-bar">
<h2>➕ Add Blog</h2>
</div>
<div class="card">
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Title</label>
<input type="text" name="title" required>
</div>
<div class="form-group">
<label>Short Description</label>
<textarea name="short_description" rows="3"></textarea>
</div>
<div class="form-group">
<label>Full Content</label>
<textarea name="content" rows="6"></textarea>
</div>
<div class="form-group">
<label>Read Time</label>
<input type="text" name="read_time" placeholder="5 min read">
</div>
<div class="form-group">
<label>Category</label>
<select name="category_id">
<option value="">Select Category</option>
<?php
$cat = mysqli_query($conn, "SELECT id,name FROM blog_categories");
while($c = mysqli_fetch_assoc($cat)){
echo "<option value='{$c['id']}'>{$c['name']}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>Upload Image</label>
<input type="file" name="image">
</div>
<button name="submit" class="btn btn-primary">
<i class="fa fa-save"></i> Save Blog
</button>
<a href="index.php" class="btn">Cancel</a>
</form>
</div>
<?php include('../includes/footer.php'); ?>


PK 99