Edit chatroom messages endpoint

This commit is contained in:
2025-08-24 20:26:36 -07:00
parent a7993fc054
commit d2251781e3

View File

@@ -0,0 +1,32 @@
<?php
require __DIR__ . '/../incl/util.php';
setPlainHeader();
checkClientDatabaseVersion();
$post = getPostData();
$id = $post['id'] ?? '';
$content = $post['content'] ?? '';
$token = $post['token'] ?? '';
$username = $post['username'] ?? '';
if (!preg_match('/^[ a-zA-Z0-9!@#\$%\^&\*\(\)_\+\-=\[\]\{\};\':",\.<>\/\?\\\\|`~]+$/', $content)) exit;
$conn = newConnection();
$stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND username = ?");
$stmt->bind_param("ss", $token, $username);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if (!$row) exit;
$stmt->close();
$user_id = $row["id"];
$content = base64_encode($content);
$stmt = $conn->prepare("UPDATE chats SET content = ? WHERE userId = ? AND id = ?");
$stmt->bind_param("sii", $content, $user_id, $id);
$stmt->execute();
$stmt->close();
$conn->close();