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)
);