<?php
session_start();
include '../models/db_connection.php';  // Database connection

if (isset($_POST['receiver'], $_POST['message'])) {
    $sender_id = $_SESSION['user'];  // Assuming the sender is logged in
    $receiver_id = $_POST['receiver'];
    $message = $_POST['message'];

    $stmt = mysqli_query($conn,"INSERT INTO messages (sender_id, receiver_id, message) VALUES ('$sender_id', '$receiver_id', '$message')");
    if ($stmt) {
        echo "<script>
        alert('Message sent successfully');
        window.location.href = 'send.php';
    </script>";
    }
}
