Help with friends system.
Posted: Tue Oct 14, 2008 7:29 am
Hey guys,
I'm new here so please move this post to a more correct location if I have posted in the wrong area.
I couldn't see a more suitable area, but I am tired so I may have overlooked something.
Anyway my problem is, I have a friends system for my basic social networking site and I'm having trouble with a couple of things.
1. When a user requests to be friends with another, that user should not be able to request again - this doesn't happen.
The message 'You are already friends with this user' appears, or sometimes it sends a second request. (Code attached below)
2. When two users become friends they should not be able to request to be friends either, again this doesn't happen.
This really has me stumped and I don't want to add more to the friend feature until I have this straightened out.
Any help would be greatly appreciated!
Thankyou in advance,
Aldur.
I'm new here so please move this post to a more correct location if I have posted in the wrong area.
I couldn't see a more suitable area, but I am tired so I may have overlooked something.
Anyway my problem is, I have a friends system for my basic social networking site and I'm having trouble with a couple of things.
1. When a user requests to be friends with another, that user should not be able to request again - this doesn't happen.
The message 'You are already friends with this user' appears, or sometimes it sends a second request. (Code attached below)
2. When two users become friends they should not be able to request to be friends either, again this doesn't happen.
This really has me stumped and I don't want to add more to the friend feature until I have this straightened out.
Any help would be greatly appreciated!
Thankyou in advance,
Aldur.
Code: Select all
$email=($_SESSION['email']);
$email2=($_SESSION['email2']);
$get = mysql_query( "SELECT * FROM `friend_requests` WHERE `by` = '$email' ");
$getarray = mysql_fetch_array($get);
$by = $getarray[by];
$by2 = $getarray[email];
$get2 = mysql_query( "SELECT * FROM `friends` WHERE `friendemail` = '$by' ");
$get2array = mysql_fetch_array($get2);
$e1=$get2array[email];
$e2=$get2array[friendemail];
$get3 = mysql_query( "SELECT * FROM `users` WHERE `email` = '$by' ");
$get3array = mysql_fetch_array($get3);
$name=$get3array[name];
$surname=$get3array[surname];
if ($email2==$email){
echo "You can't add yourself!";
exit;
}
if($email2 == $e1 or $email == $e2){
echo "You are already friends with this user!<br />";
exit;
}
if($email == $by or $email2 == $by2){
echo "You have already requested to be this user's friend!<br />";
exit;
}
else{
if ($_SESSION['email2']){
$email = htmlspecialchars($_SESSION['email2']);
$by = $_SESSION['email'];
$query = mysql_query("INSERT INTO `friend_requests` ( `email` , `by` ) VALUES ( '$email' , '$by' )");
echo ( "$name $surname has been sent a request you must now wait for it to be accepted" );
} else {
echo ( "No request was made" );
}
}
unset($_SESSION['email2']);