Welcome Guest [Log In] [Register]
Add Reply
Question?; Friends
Topic Started: Jul 24 2008, 03:01 PM (421 Views)
scottjcampbell
Member Avatar

Hi, i have been trying to sort this out since i first implimented the script on my site about 3 days ago (i think).

Is it possible to make it so a user can only be friends with another user once, sorry if this isn't explained very well, i am not good at explaining things.

This might help explain: DUMMYUSER1 becomes friends with DUMMYUSER2, DUMMYUSER1 can still add DUMMYUSER2 as a friend, so when you click on the friends list there can be multiple DUMMYUSER2's, is it possible to stop this?

Thanks, SCOTT CAMPBELL
Offline Profile Quote Post Goto Top
 
feartec

maybe i can help, wait for a few minutes i will look at the friends script ;).
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Hmm I was thinking somthing like this so that they cant send a message to themselves:

Code:
 

if ($by == ($session->User)){
echo "You cant add yourself.";
}
else{
}


So maybe, could tweak this so:

Code:
 

if ($username == ($getfriends)){
echo "You cant add someone who is already your friend.";
}
else{
}


This obviously wont work as $getfriends wouldnt work but its just an idea.

Edited by JakkyD, Jul 24 2008, 03:38 PM.
Offline Profile Quote Post Goto Top
 
feartec

Change your friendrequest.php to this:
Don't forget to make a backup first.
Code:
 

<title>Friends Request</title>
<head>
<link rel="stylesheet" type="text/css"
href="style/main.css" />
</head>


<blockquote>
<div align="center">
<? include("include/session.php"); ?>
<? include 'including/logo.php'; ?>
<? include 'including/menu.php'; ?>


<table width="922" height="31" border="2">
<tr>
<td height="23" bordercolor="#FFFFFF" bgcolor="#FFFFFF">

<p align="center" class="logotext">Request to be Friend </p>
<p>
<?
session_start(); //starts session

/* Requested Username error checking */


$req_user = trim($_GET['user']);

if ($session->logged_in){ //checks user is logged in

if ($req_user){ //gets username
$username = htmlspecialchars($req_user); //friend
$by = $session->username; //you

$getfriends = mysql_query( "SELECT * FROM `friends` WHERE `username` = '$session->username'" );

if($username == $getfriends){
?>
<? echo $username; ?> is already been added to your friendlist.
<?
}
else{
?>
$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
}
?>

</p></td>
</tr>
</table>
</div>
</blockquote>


Edited by feartec, Jul 24 2008, 04:04 PM.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Nice. I didnt actually relise I was kinda right. Thats if feartecs' works :P
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

Thanks for the scripts but this still isn't working for me. I have modified the scripts to try to make them work but they still wont.

I moved the include for session.php to the top because i was gettin a php error that the headers were already sent.
I also removed the ?> from:
Code:
 

}
else{
?> <<<-- /////////HERE/////////
$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
?>
<?

as i was getting that written into my page instead of PHP performing this action.

Still, i annot make it work, i have tested it and i can still add a user multiple times, even after they have accepted the request.

Thanks, SCOTT CAMPBELL
Edited by scottjcampbell, Jul 24 2008, 05:47 PM.
Offline Profile Quote Post Goto Top
 
feartec

that wrong script!!

this is the good one:
Code:
 

}
else{
?>
<?
$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
?>
<?
}
?>
Edited by feartec, Jul 24 2008, 06:16 PM.
Offline Profile Quote Post Goto Top
 
feartec

maybe can you give me the error you get.
Offline Profile Quote Post Goto Top
 
scottjcampbell
Member Avatar

Which one? Before i move the session? or another one?
Offline Profile Quote Post Goto Top
 
feartec

Which error do you get by mine friendsrequest.php that i post few hours ago.
Code:
 

<title>Friends Request</title>
<head>
<link rel="stylesheet" type="text/css"
href="style/main.css" />
</head>


<blockquote>
<div align="center">
<? include("include/session.php"); ?>
<? include 'including/logo.php'; ?>
<? include 'including/menu.php'; ?>


<table width="922" height="31" border="2">
<tr>
<td height="23" bordercolor="#FFFFFF" bgcolor="#FFFFFF">

<p align="center" class="logotext">Request to be Friend </p>
<p>
<?
session_start(); //starts session

/* Requested Username error checking */


$req_user = trim($_GET['user']);

if ($session->logged_in){ //checks user is logged in

if ($req_user){ //gets username
$username = htmlspecialchars($req_user); //friend
$by = $session->username; //you

$getfriends = mysql_query( "SELECT * FROM `friends` WHERE `username` = '$session->username'" );

if($username == $getfriends){
?>
<? echo $username; ?> is already been added to your friendlist.
<?
}
else{
?>
$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
}
?>

</p></td>
</tr>
</table>
</div>
</blockquote>


Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Friends System · Next Topic »
Add Reply