<?php
include 'db_connection.php';

$message_id = isset($_POST['message_id']) ? intval($_POST['message_id']) : 0;
$new_message = isset($_POST['message']) ? trim($_POST['message']) : '';

if ($message_id > 0 && !empty($new_message)) {
    $sql = "UPDATE group_messages SET message = ? WHERE message_id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("si", $new_message, $message_id);
    if ($stmt->execute()) {
        echo json_encode(['status' => 'success']);
    } else {
        echo json_encode(['status' => 'error', 'message' => 'Failed to update message']);
    }
    $stmt->close();
} else {
    echo json_encode(['status' => 'error', 'message' => 'Invalid input']);
}

$conn->close();
?>
