-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape_delete.php
More file actions
44 lines (40 loc) · 1.2 KB
/
shape_delete.php
File metadata and controls
44 lines (40 loc) · 1.2 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
39
40
41
42
43
44
<?php
// shape_delete.php
include 'config.php';
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
header("location: index.php");
exit;
}
if (isset($_GET["id"]) && !empty(trim($_GET["id"]))) {
$shape_id = trim($_GET["id"]);
// First, get the image path to delete the file
$stmt = $conn->prepare("SELECT image FROM shapes WHERE id = ?");
$stmt->bind_param("i", $shape_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$shape = $result->fetch_assoc();
// Delete the image file if it exists
if (!empty($shape['image']) && file_exists($shape['image'])) {
unlink($shape['image']);
}
}
$stmt->close();
// Now, delete the record from the database
$sql = "DELETE FROM shapes WHERE id = ?";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("i", $shape_id);
if ($stmt->execute()) {
header("location: shape_master.php");
exit();
} else {
echo "Oops! Something went wrong. Please try again later.";
}
}
$stmt->close();
$conn->close();
} else {
header("location: shape_master.php");
exit();
}
?>