-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_category.php
executable file
·39 lines (33 loc) · 1.03 KB
/
delete_category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// delete_category.php
require 'auth.php';
////require_once 'permissions.php';
redirect_if_not_logged_in();
require_non_player();
if (!is_admin()) die("Access denied.");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
// Verify if the category exists before attempting deletion
$stmt = $conn->prepare("SELECT id FROM categories WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$stmt = $conn->prepare("DELETE FROM categories WHERE id = ?");
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
header("Location: insert_category.php");
exit;
} else {
echo "<p class='error'>Error deleting category: {$stmt->error}</p>";
}
$stmt->close();
} else {
echo "<p class='error'>Category not found or already deleted.</p>";
}
$result->close();
}
?>