<?php
include('connection.php');

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

    // Perform the SQL query to remove the exact member name from the group
    $memberNameSafe = mysqli_real_escape_string($conn, trim($memberName));
    $sql = "UPDATE groups SET member = REPLACE(member, '$memberName,', '') WHERE id = '$groupId'";

    if (mysqli_query($conn, $sql)) {
        echo 'success';
    } else {
        echo 'error';
    }
}

mysqli_close($conn);
?>
