-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
61 lines (49 loc) · 1.24 KB
/
update.php
File metadata and controls
61 lines (49 loc) · 1.24 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
<?php
require_once "db.php";
if (!isset($_GET['id'])) {
header("Location: read.php");
exit;
}
$id = (int) $_GET['id'];
// Fetch existing note
$stmt = $conn->prepare("SELECT title, content FROM notes WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$note = $result->fetch_assoc();
if (!$note) {
die("Note not found");
}
// Handle update
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$updateStmt = $conn->prepare(
"UPDATE notes SET title = ?, content = ? WHERE id = ?"
);
$updateStmt->bind_param("ssi", $title, $content, $id);
$updateStmt->execute();
header("Location: read.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Note</title>
</head>
<body>
<a href="index.php" style="display:inline-block; margin-bottom:15px;">
← Home
</a>
<h2>Edit Note</h2>
<form method="POST">
<input type="text" name="title"
value="<?= htmlspecialchars($note['title']) ?>" required>
<br><br>
<textarea name="content" rows="5" required><?= htmlspecialchars($note['content']) ?></textarea>
<br><br>
<button type="submit">Update Note</button>
</form>
</body>
</html>