<?php
// Include the database connection file
require_once 'connection.php';

// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Escape user inputs for security (assuming connection is established)
    $user_email = $conn->real_escape_string($_POST['user_email']);
    $friend_email = $conn->real_escape_string($_POST['friend_email']);

    // Attempt delete query execution for both cases
    $delete_sql = "DELETE FROM `friend_table` 
                   WHERE (`user_email`='$user_email' AND `friend_email`='$friend_email') 
                   OR (`user_email`='$friend_email' AND `friend_email`='$user_email')";
    
    if ($conn->query($delete_sql) === TRUE) {
        if ($conn->affected_rows > 0) {
            echo "Friend removed successfully.";
        } else {
            echo "Friend not found for this user.";
        }
    } else {
        echo "Error: " . $delete_sql . "<br>" . $conn->error;
    }
}

$conn->close();
?>
