-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_tasks.php
36 lines (31 loc) · 963 Bytes
/
delete_tasks.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
36
<?php
include 'db.php'; // Including database connection
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php"); // Redirect to login page if not logged in
exit();
}
// Check if TASK_ID is provided in the URL
if (isset($_GET['task_id'])) {
$task_id = $_GET['task_id'];
// Prepare DELETE SQL statement
$stmt = $conn->prepare("DELETE FROM TO_DO_LIST WHERE TASK_ID = ? AND ID = ?");
$stmt->bind_param('ii', $task_id, $_SESSION['user_id']);
// Execute the query
if ($stmt->execute()) {
// Redirect to task view page after successful deletion
header("Location: view_tasks.php");
exit();
} else {
echo "Error deleting task: " . $stmt->error;
}
$stmt->close();
} else {
echo "No task ID provided for deletion.";
}
$conn->close();
?>