-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteComponent.php
35 lines (35 loc) · 1.27 KB
/
deleteComponent.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
<?php
require 'mysql.php';
mysqli_select_db($conn, $dbName);
if (isset($_POST['component_id'])) {
$component_id = $_POST['component_id'];
$sql = "DELETE FROM $tableComponentName WHERE componentName = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $component_id);
if ($stmt->execute()) {
$sql2 = "SELECT * FROM $tableComponentsItemsName WHERE componentName = '".$component_id."'";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
while($row2 = $result2->fetch_assoc()) {
$sql2 = "DELETE FROM $tableComponentsItemsName WHERE componentName = ?";
$stmt2 = $conn->prepare($sql2);
$stmt2->bind_param("s", $component_id);
if ($stmt2->execute()) {
$uploadDir = 'img/';
$filePathToDelete = $uploadDir . $row2['imgPath'];
if (file_exists($filePathToDelete)) {
unlink($filePathToDelete);
}
}
}
}
$result2->close();
header("Location: adminPanel.php");
exit();
} else {
echo "Ошибка при удалении компонента: " . $conn->error;
}
$stmt->close();
}
$conn->close();
?>