-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_note.php
executable file
·55 lines (46 loc) · 1.36 KB
/
edit_note.php
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
<?php
////require_once 'permissions.php';
session_start();
require 'conn.php';
if (!isset($_GET['id'])) {
header('Location: notepad.php');
exit();
}
$note_id = $_GET['id'];
$user_id = $_SESSION['user_id'];
// Fetch the note to edit
$stmt = $pdo->prepare("SELECT * FROM user_notes WHERE id = ? AND user_id = ?");
$stmt->execute([$note_id, $user_id]);
$note = $stmt->fetch();
if (!$note) {
die("Note not found!");
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$content = $_POST['content'];
$stmt = $pdo->prepare("UPDATE user_notes SET title = ?, content = ? WHERE id = ? AND user_id = ?");
$stmt->execute([$title, $content, $note_id, $user_id]);
header('Location: notepad.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 Note</title>
<script src="https://cdn.ckeditor.com/4.20.2/standard/ckeditor.js"></script>
</head>
<body>
<h1>Edit Note</h1>
<form method="POST">
<input type="text" name="title" value="<?= htmlspecialchars($note['title']) ?>" required>
<textarea name="content" id="editor"><?= $note['content'] ?></textarea>
<button type="submit">Update Note</button>
</form>
<script>
CKEDITOR.replace('editor');
</script>
</body>
</html>