Repository navigation
Expand file tree
/
Copy pathedit_task.php
More file actions
92 lines (75 loc) · 3.17 KB
/
Copy pathedit_task.php
File metadata and controls
92 lines (75 loc) · 3.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
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
<?php
require_once 'config.php';
if (isset($_GET['id']) && !empty($_GET['id'])) {
$taskId = $_GET['id'];
$sql = "SELECT id, title, category, description FROM tasks WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $taskId, PDO::PARAM_INT);
$stmt->execute();
$task = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$task) {
echo "Tâche introuvable.";
exit;
}
} else {
echo "Aucune tâche à modifier.";
exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$task_name = $_POST['taskName'];
$task_description = $_POST['taskDescription'];
$task_category = $_POST['taskCategory'];
if (!empty($task_name) && !empty($task_description) && !empty($task_category)) {
$sql = "UPDATE tasks SET title = :title, description = :description, category = :category WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':title', $task_name);
$stmt->bindParam(':description', $task_description);
$stmt->bindParam(':category', $task_category);
$stmt->bindParam(':id', $taskId, PDO::PARAM_INT);
if ($stmt->execute()) {
header("Location: tasks_list.php");
exit;
} else {
echo "Erreur lors de la modification de la tâche.";
}
} else {
echo "Veuillez remplir tous les champs.";
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modifier la Tâche</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<?php include_once 'header.php'; ?>
<div class="container mt-5">
<div class="card shadow-lg p-4">
<h2 class="text-center text-primary mb-4">Modifier la Tâche</h2>
<form method="POST" action="">
<div class="mb-3">
<label for="taskName" class="form-label">Nom de la tâche</label>
<input type="text" name="taskName" id="taskName" class="form-control" value="<?php echo htmlspecialchars($task['title']); ?>" required>
</div>
<div class="mb-3">
<label for="taskCategory" class="form-label">Catégorie</label>
<input type="text" name="taskCategory" id="taskCategory" class="form-control" value="<?php echo htmlspecialchars($task['category']); ?>" required>
</div>
<div class="mb-3">
<label for="taskDescription" class="form-label">Description de la tâche</label>
<textarea name="taskDescription" id="taskDescription" class="form-control" rows="3" required><?php echo htmlspecialchars($task['description']); ?></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Enregistrer les modifications</button>
</form>
<div class="text-center mt-3">
<a href="tasks_list.php" class="btn btn-secondary">Retour à la liste des tâches</a>
</div>
</div>
</div>
<?php include_once 'footer.php'; ?>
</body>
</html>