<?php
require_once 'connection.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $groupId = $_POST['groupId'];
    $senderEmail = $_POST['senderEmail'];
    $messageContent = $_POST['messageContent'];
    $messageType = $_POST['messageType'];

    // Prepare an insert statement
    $stmt = $conn->prepare("INSERT INTO `groupmessagetable` (`groupId`, `senderEmail`, `messageContent`, `messageType`) VALUES (?, ?, ?, ?)");
    // Bind parameters (four string values)
    $stmt->bind_param("ssss", $groupId, $senderEmail, $messageContent, $messageType);

    if ($stmt->execute()) {
        echo "Message sent successfully.";
    } else {
        echo "Error: " . $stmt->error;
    }

    $stmt->close();
}

$conn->close();
?>
