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
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
<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
<a href='newfriends.php'>Friend Requests</a>
Any problems let me no ;)
Chris..