25 lines
454 B
PHP
25 lines
454 B
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$post_id = $_GET['id'] ?? null;
|
|
|
|
if ($post_id) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("DELETE FROM posts WHERE id = ?");
|
|
$stmt->execute([$post_id]);
|
|
} catch (PDOException $e) {
|
|
die("Error: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
header('Location: admin.php');
|
|
exit;
|
|
?>
|