Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 176
0 Users 7 Guests Online

Friends system

First you need to run the following in PHPmyAdmin

Code

CREATE TABLE `friend_requests` (
`id` int(10) NOT NULL auto_increment,
`username` varchar(225) NOT NULL default '',
`by` varchar(225) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

CREATE TABLE `friends` (
`id` int(10) NOT NULL auto_increment,
`friendname` varchar(225) NOT NULL default '',
`username` varchar(225) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;


You may want to add them seperatly

Right i have tested this system so it should work

---

Call this page friendrequest.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?
session_start
(); //starts session
include "config.php"//include config

if ($logged[username]){ //checks user is logged in

if ($_GET[user]){ //gets username
$username htmlspecialchars($_GET[user]); //friend
$by $logged[username]; //you
$query mysql_query("INSERT INTO `friend_requests` ( `username` , `by` ) VALUES ( '$username' , '$by' )"); //inserts the request
echo ( "$username has been sent a request you must now wait for it to be accepted" ); //echos completion
} else {
echo ( 
"No request was made" ); // or no request sent
}
} else {
echo ( 
"You need to be logged in" ); //not logged in
}
?>


Ok, now call this one newfriends.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?
session_start
(); // starts sessions
include "config.php"// inlcudes config

if ($logged[username]) { //checks user is logged in
switch ($_GET[friends]) { //allows multiple pages
default:
$get mysql_query"SELECT * FROM `friend_requests` WHERE `username` = '$logged[username]' "); //gets requests
while ($reqs mysql_fetch_array($get))
{

echo ( 
"Friend Requests
$reqs[by] wants to be friends with you.
<a href='newfriends.php?friends=accept&user=
$reqs[by]'>Accept</a><br/>
<a href='newfriends.php?friends=delete&user=
$reqs[by]'>Delete</a>" ); //displays requests and shows accept delete links
}
break;

case 
'accept'//accept page
if ($_GET[user]) { //get username

$add mysql_query"INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$logged[username]') "); // add to your friends list
$delete mysql_query"DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]' "); // deletes friend request
echo ( "$_GET[user] has been added as a friend and the request has been deleted" ); // echos the completion
}
break; 
//ends accept page

case 'delete'// delete page
if ($_GET[user]) { //gets username
$delete mysql_query"DELETE FROM `friend_requests` WHERE `by` = '$_GET[user]' "); // deletes friend request
echo ( "$_GET[user]'s request has been deleted" ); // echos completion
}
break; 
//ends delete page
// ends switch
} else {
echo ( 
"You need to be logged in" ); // not logged in
}
?>


Right now to add the requests in members.php

Find:
PHP Code
1
2
3
4
5
6
7
echo "<fieldset style='width: 350'>
<b>$user[username]'s Profile</b><br><br>
Email: $user[email]<br>
Location: $user[location]<br>
Sex: $user[sex]<br>
Age: $user[age]


Add:
PHP Code
1
2
3
<a href='friendrequest.php?user=$user[username]'>Add as Friend</a>


Adn now go to the page where your links are..

should be login.php

add in there

PHP Code
1
2
<a href='newfriends.php'>Friend Requests</a>


Any problems let me no ;)

Chris..
new2old
Author:
Views:
3907
Rating:
Posted on Thursday 21st August 2008 at 04:58 PM
saintpaulos
saintpaulos
Actually I sorted it. Showed I learned something! lol Thanks! :)
Posted on Thursday 21st August 2008 at 02:09 PM
saintpaulos
saintpaulos
I love this!

Its not a problem, but if you have no friends you get a blank page. How would you add, 'Sorry no friend requests'?
Posted on Friday 8th August 2008 at 05:17 AM
UrbanTwitch
UrbanTwitch
Time to fix a bug. I found out that if you send someone a friend request and they accept. If you go to their user profile it shows you as their friend. But if you go to your profile (you'd expect to see them as your friend) it shows no friends.

How do we fix this?

Find in newrequests.php:

PHP Code
1
$add = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$_GET[user]' , '$logged[username]') "); // add to your friends list


and add below it:

PHP Code
1
$add2 = mysql_query( "INSERT INTO `friends` (`friendname` , `username`) VALUES ('$logged[username]' , '$_GET[user') "); // fix friend bug


Enjoy!
Posted on Sunday 20th July 2008 at 07:25 PM
Dava
Dava
ill write it later and post it for you
Posted on Sunday 20th July 2008 at 12:58 AM
UrbanTwitch
UrbanTwitch
Can you do it Dava? :-P
Posted on Friday 18th July 2008 at 08:12 PM
Dava
Dava
do an if class urban just say if $friendname = $username hide else show :P that should be pretty basic
Posted on Friday 16th May 2008 at 06:49 PM
jambomb
jambomb
brill!
Posted on Tuesday 8th April 2008 at 05:57 PM
Dalez
Dalez
Yeah, what Urban said, that would be cool.
Posted on Monday 7th April 2008 at 09:52 PM
UrbanTwitch
UrbanTwitch
Is there a way to make it after you be someones friend the "Add As Friend" doesn't show up anymore?
Posted on Sunday 17th February 2008 at 11:42 AM
Crown
Crown
Yes i am ? :3