What are some common challenges faced when implementing a MySQL-PHP friendship system?

One common challenge faced when implementing a MySQL-PHP friendship system is handling friend requests and approvals efficiently. To solve this, you can create a separate table in the database to store pending friend requests and update the status once they are approved or rejected.

// Create a table to store pending friend requests
CREATE TABLE friend_requests (
    id INT AUTO_INCREMENT PRIMARY KEY,
    sender_id INT,
    receiver_id INT,
    status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending'
);

// Query to send a friend request
$sender_id = 1;
$receiver_id = 2;

$query = "INSERT INTO friend_requests (sender_id, receiver_id) VALUES ($sender_id, $receiver_id)";
$result = mysqli_query($connection, $query);

if($result) {
    echo "Friend request sent successfully";
} else {
    echo "Error sending friend request";
}