-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteProduct.php
More file actions
38 lines (30 loc) · 1 KB
/
Copy pathdeleteProduct.php
File metadata and controls
38 lines (30 loc) · 1 KB
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
<?php
include 'db.php';
if (isset($_POST['product_id']) && isset($_POST['productCategory'])) {
$productId = $_POST['product_id'];
$categoryName = $_POST['productCategory'];
$query = "SELECT file, id_category FROM handicrafts WHERE id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $productId);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$file = $row['file'];
$id_category = $row['id_category'];
$filePath = 'images/category/' . $categoryName . '/' . $file;
if (file_exists($filePath)) {
unlink($filePath);
}
$stmt->close();
$deleteQuery = "DELETE FROM handicrafts WHERE id = ?";
$stmt = $conn->prepare($deleteQuery);
$stmt->bind_param("i", $productId);
if ($stmt->execute()) {
header('location: categories.php?id_category=' . $id_category);
exit();
} else {
echo "Wystąpił błąd podczas usuwania produktu.";
}
$stmt->close();
$conn->close();
}