32 lines
802 B
PHP
32 lines
802 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$paper_id = $_GET['id'];
|
|
$pdo = db();
|
|
|
|
// Optional: Check if paper exists before deleting
|
|
$stmt = $pdo->prepare("SELECT id FROM papers WHERE id = ?");
|
|
$stmt->execute([$paper_id]);
|
|
if ($stmt->rowCount() === 0) {
|
|
// Paper not found, maybe already deleted
|
|
header("Location: index.php?error=notfound");
|
|
exit;
|
|
}
|
|
|
|
// Delete the paper
|
|
try {
|
|
$stmt = $pdo->prepare("DELETE FROM papers WHERE id = ?");
|
|
$stmt->execute([$paper_id]);
|
|
header("Location: index.php?success=deleted");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
// Log error if you have a logging system
|
|
header("Location: index.php?error=deletfailed");
|
|
exit;
|
|
}
|