<?php
session_start();
include('db_connection.php');



$friend_id = isset($_POST['friend_id']) ? intval($_POST['friend_id']) : 0;
$user_id = $_SESSION['student_id'];

if ($friend_id > 0 && $friend_id !== $user_id) {
    $sql = "INSERT INTO student_requests (student_id, requested_id, status) VALUES (?, ?, 'pending')";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ii", $user_id, $friend_id);
    if ($stmt->execute()) {
        echo "Friend request sent.";
    } else {
        echo "Error sending friend request.";
    }
    $stmt->close();
}

$conn->close();
?>
