-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
41 lines (34 loc) · 854 Bytes
/
edit.php
File metadata and controls
41 lines (34 loc) · 854 Bytes
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
<?php
require 'db.php';
if (!isset($_GET['id'])) {
die("Invalid Request");
}
$id = $_GET['id'];
// Fetch existing task
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE id = :id");
$stmt->execute(['id' => $id]);
$task = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$task) {
die("Task not found");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$title = $_POST['title'];
$stmt = $pdo->prepare("UPDATE tasks SET title = :title WHERE id = :id");
$stmt->execute(['title' => $title, 'id' => $id]);
header("Location: index.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Task</title>
</head>
<body>
<h1>Edit Task</h1>
<form method="post">
<input type="text" name="title" value="<?= htmlspecialchars($task['title']) ?>" required>
<button type="submit">Update</button>
</form>
</body>
</html>