-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.php
More file actions
43 lines (30 loc) · 972 Bytes
/
delete.php
File metadata and controls
43 lines (30 loc) · 972 Bytes
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
40
41
42
43
<?php
include 'db.php';
if (isset($_GET['deleteid'])) {
$categoryId = $_GET['deleteid'];
$pathQuery = "SELECT category_name FROM categories WHERE id = ?";
$stmt = $conn->prepare($pathQuery);
$stmt->bind_param("i", $categoryId);
$stmt->execute();
$result = $stmt->get_result();
$categoryName = $result->fetch_assoc()['category_name']; // Poprawny sposób pobrania nazwy kategorii
$stmt->close();
$folderPath = 'images/category/' . $categoryName;
$files = glob($folderPath . '/*');
foreach ($files as $file) {
unlink($file);
}
rmdir($folderPath);
$deleteQuery = "DELETE FROM categories WHERE id = ?";
$stmt = $conn->prepare($deleteQuery);
$stmt->bind_param("i", $categoryId);
if ($stmt->execute()) {
header('location: index.php');
exit();
} else {
echo "Wystąpił błąd podczas usuwania kategorii.";
}
$stmt->close();
$conn->close();
}
?>