-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_note.php
More file actions
39 lines (30 loc) · 931 Bytes
/
Copy pathsave_note.php
File metadata and controls
39 lines (30 loc) · 931 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
<?php
require_once '/home/chzruk/public_html/public/bootstrap.php';
if (!isset($_SESSION['user_id']) || !is_numeric($_SESSION['user_id'])) {
http_response_code(403);
exit("Not authenticated");
}
$user_id = (int)$_SESSION['user_id'];
$conn = new mysqli('', '', '', '');
if ($conn->connect_error) {
http_response_code(500);
exit("Connection failed");
}
if (!isset($_POST['content'])) {
http_response_code(400);
exit("No content");
}
$content = $_POST['content'];
// INSERT or UPDATE (requires UNIQUE INDEX on user_id)
$stmt = $conn->prepare("
INSERT INTO note (user_id, content, updated_at)
VALUES (?, ?, NOW())
ON DUPLICATE KEY UPDATE
content = ?,
updated_at = NOW()
");
$stmt->bind_param("iss", $user_id, $content, $content);
$success = $stmt->execute();
echo $success ? "Note saved" : "Save failed";
$stmt->close();
$conn->close();