-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_task.php
More file actions
109 lines (96 loc) · 3.51 KB
/
edit_task.php
File metadata and controls
109 lines (96 loc) · 3.51 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
session_start();
include 'db.php';
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
// Fetch task details
if (isset($_GET['id'])) {
$task_id = $_GET['id'];
$sql = "SELECT * FROM tasks WHERE id = :task_id AND user_id = :user_id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':task_id', $task_id);
$stmt->bindParam(':user_id', $_SESSION['user_id']);
$stmt->execute();
$task = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$task) {
echo "Task not found or access denied.";
exit;
}
}
// Update task
if (isset($_POST['update_task'])) {
$title = $_POST['title'];
$description = $_POST['description'];
$status = $_POST['status'];
$deadline = $_POST['deadline'];
try {
$sql = "UPDATE tasks SET title = :title, description = :description, status = :status, deadline = :deadline WHERE id = :task_id AND user_id = :user_id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':description', $description);
$stmt->bindParam(':status', $status);
$stmt->bindParam(':deadline', $deadline);
$stmt->bindParam(':task_id', $task_id);
$stmt->bindParam(':user_id', $_SESSION['user_id']);
$stmt->execute();
header("Location: dashboard.php");
exit;
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Task</title>
<link rel="stylesheet" href="css/style.css">
</head>
<style>
body {
background-image: url('bg1.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
</style>
<body> <!-- Navigation Bar -->
<nav>
<div class="nav-container">
<div class="logo">TaskManager</div>
<ul>
<!-- <li><a href="home.php">Home</a></li> -->
<li><a href="dashboard.php">Dashboard</a></li>
</ul>
<a href="logout.php" class="logout">Logout</a>
</div>
</nav>
<h2>Edit Task</h2>
<form action="" method="POST">
<label for="title">Title:</label>
<input type="text" id="title" name="title" value="<?php echo htmlspecialchars($task['title']); ?>" required>
<br><br>
<label for="description">Description:</label>
<textarea id="description" name="description"><?php echo htmlspecialchars($task['description']); ?></textarea>
<br><br>
<label for="status">Status:</label>
<select id="status" name="status">
<option value="To Do" <?php if ($task['status'] == 'To Do') echo 'selected'; ?>>To Do</option>
<option value="In Progress" <?php if ($task['status'] == 'In Progress') echo 'selected'; ?>>In Progress</option>
<option value="Completed" <?php if ($task['status'] == 'Completed') echo 'selected'; ?>>Completed</option>
</select>
<br><br>
<label for="deadline">Deadline:</label>
<input type="date" id="deadline" name="deadline" value="<?php echo htmlspecialchars($task['deadline']); ?>" required>
<br><br>
<button type="submit" name="update_task">Update Task</button>
</form>
<a href="dashboard.php">Back to Dashboard</a>
<script src="js/scripts.js"></script>
</body>
</html>