Hi ive been having a lot of trouble with this and spent the last 2 days trial and erroring it, so i finally bit the bullet and am just asking for help,
basically im creating a simple friend request and accepting form using mysql and php.
i already have it set up so you type in the friends username and hit enter, and then it inserts your username and theirs into a DB with a “0” for the status.
i only need one row per friendship, as it wont matter who friended whom.
Right now im having a problem accepting and denying the friendships.
I would like to have a table with 3 columns, the requesting friend username, an accept button, and a deny button.
THe table will obviosly have to automatically add rows based on how many requests you have pending.
I am unable to make the buttons update only the row they belong to, i know i need to do some sort of counting to individually name each button but i am new to php and i have yet to figure it out
Database is set up as:
ID----peer1(requesting)----Peer2(requested)----Status
1------test1---------------------test2--------------------0
heres where my DB is updated:
[php]
$addedpeer = mysql_real_escape_string(trim($_POST[‘addedpeer’]));
$addingpeer = $_SESSION[‘SESS_USER_NAME’];
$qry = “INSERT INTO peers (peer1, peer2, status) VALUES (’$addingpeer’, ‘$addedpeer’, ‘0’)”;
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header(“location: friends.php”);
exit();
}
else {
die(“Query failed hard”);
}
[/php]
[b]So that inserts the request with a 0
and i scrapped everything and started over so heres my basic set up without the counter for the accept/deny part:[/b]
[php]$addedpeer = $_SESSION[‘SESS_USER_NAME’];
$requests = mysql_query( “SELECT * FROM peers WHERE peer2 = ‘$addedpeer’ AND status = ‘0’” );
$result = mysql_query($requests);
while ($row = mysql_fetch_array($result))
{
echo "
";
};
//Accept button should:
“UPDATE peers SET status = ‘1’ WHERE id=’$id’”;
//Deny button chould:
“DELETE FROM peers WHERE id = ‘$id’”;
[/php]
I know im missing some variables but i threw this together so you can help me set them.
Any help or advise you can give would be greatly appreciated, ive been all over the internet looking for an answer