-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_links_delete.php
More file actions
43 lines (36 loc) · 1.17 KB
/
shared_links_delete.php
File metadata and controls
43 lines (36 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
// shared_links_delete.php
include 'config.php'; // Only need db connection and session start
// Check if user is logged in
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
header("location: index.php");
exit;
}
// Check if ID parameter is set
if (isset($_GET["id"]) && !empty(trim($_GET["id"]))) {
// Prepare a delete statement
$sql = "DELETE FROM shared_links WHERE id = ?";
if ($stmt = $conn->prepare($sql)) {
// Bind variables to the prepared statement as parameters
$stmt->bind_param("i", $param_id);
// Set parameters
$param_id = trim($_GET["id"]);
// Attempt to execute the prepared statement
if ($stmt->execute()) {
// Records deleted successfully. Redirect to landing page.
header("location: shared_links.php");
exit();
} else {
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
$stmt->close();
// Close connection
$conn->close();
} else {
// ID parameter is missing. Redirect to error page or landing page.
header("location: shared_links.php");
exit();
}
?>