如何允许用户使用PHP和MySQL接受或拒绝朋友?

I was wondering how would I allow a member to accept or deny another member as a friend? How would my PHP & MySQL code look like?

Here is my PHP & MySQL code.

if (isset($_GET['fid'])){
    $friend_id = mysqli_real_escape_string($mysqli, htmlentities(strip_tags($_GET['fid'])));

    if(isset($site_id)){
        $dbc = mysqli_query($mysqli,"SELECT * FROM friends WHERE user_id = '$site_id' AND friend_id = '$friend_id'");

        if(mysqli_num_rows($dbc) == 1){
            echo '<p>Your friend has already been added!</p>';
        } else if(mysqli_num_rows($dbc) == 0){
            $dbc = mysqli_query($mysqli,"INSERT INTO friends (user_id, friend_id, date_created) VALUES ('$site_id', '$friend_id', NOW())");
        }

        if (!$dbc) {
                print mysqli_error($mysqli);
                return;
        }
    }
}

Here is the MySQL table.

CREATE TABLE friends (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL,
friend_id INT UNSIGNED NOT NULL,
date_created DATETIME NOT NULL,
PRIMARY KEY (id),
KEY user_id (user_id),
KEY friend_id (friend_id)
);

Add another field in your table called "accepted". When someone makes a friend request, set the accepted field to '0' and send a request to the friend. If the friend accepts, update the table and set the accepted field to '1'. If it is 1, then that means they are friends. If 0, then they aren't.

I'd start adding a new field to your mysql table, like state ENUM('pending','approved'). The moment one requests someone's friend state, you set the state to 'pending', when the other user approves the other's friendship the field's set to "approved".

This way you're able to determine if one's friendship was already applied.