-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_task.php
More file actions
100 lines (89 loc) · 2.5 KB
/
update_task.php
File metadata and controls
100 lines (89 loc) · 2.5 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
<?php
session_start();
include 'db.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$user_id = $_SESSION['user_id'];
// Check if the task ID is provided
if (!isset($_GET['id'])) {
header("Location: dashboard.php");
exit();
}
$task_id = $_GET['id'];
// Fetch the task to edit
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE id = ? AND user_id = ?");
$stmt->execute([$task_id, $user_id]);
$task = $stmt->fetch();
if (!$task) {
header("Location: dashboard.php");
exit();
}
// Handle the update form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['task'])) {
$updated_task = $_POST['task'];
$stmt = $pdo->prepare("UPDATE tasks SET task = ? WHERE id = ? AND user_id = ?");
$stmt->execute([$updated_task, $task_id, $user_id]);
header("Location: dashboard.php");
exit();
}
?>
<!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="style.css">
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #6a11cb, #2575fc);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 400px;
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 15px;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h2>Edit Task</h2>
<form method="POST">
<input type="text" name="task" value="<?php echo htmlspecialchars($task['task']); ?>" required>
<button type="submit">Update Task</button>
</form>
<a href="dashboard.php" style="display: block; margin-top: 10px;">Cancel</a>
</div>
</body>
</html>