forked from Xinyi-Lai/CS411_Geniuses
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop_delete.php
More file actions
executable file
·43 lines (35 loc) · 1.17 KB
/
op_delete.php
File metadata and controls
executable file
·43 lines (35 loc) · 1.17 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
<?php
include_once "db_functions.php";
//get the parameter from URL
$id = $_GET["id"];
$table=$_GET["table"];
//connect db
if ($id && ($table=="Sales" || $table=="Requests")) {
$tablekey = $table=='Sales' ? 'SaleId':'RequestId';
$conn = connectDB();
// delete image for products in Sales
if ($table=='Sales') {
$sql = "SELECT * FROM Sales WHERE SaleId=$id";
$result = $conn->query($sql);
if ($result) {
$row = mysqli_fetch_assoc($result);
$original_filepath = $row['Image'];
if(is_file($original_filepath)) {
unlink($original_filepath);
}
}
else {
$msg = "Error get path from sales: " . $sql . "<br>" . $conn->error;
}
}
$sql = "DELETE FROM $table WHERE $tablekey = '$id'";
if ($conn->query($sql)) {
$msg = "Successfully deleted.";
}
else {
$msg = "Error delete: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
//echo "<script>console.log('$msg')</script>";
?>