0){ //if there is a row with both users $relaccepted = mysql_result(mysql_query("SELECT accepted FROM relationships WHERE (ida=$ua AND idb=$ub) OR (ida=$ub AND idb=$ua)"), 0); if ($relaccepted=='y'){ //friendship confirmed return 1; }else{ $relselectb = mysql_result(mysql_query("SELECT ida FROM relationships WHERE (ida=$ua AND idb=$ub) OR (ida=$ub AND idb=$ua)"), 0); if ($relselectb==$ua){ //user A sent to user B return 2; }else{ //user B sent to user A return 3; } } }else{ //there is no row with both users return 0; } } include("http://claud.wordsfree.org/bar.php/"); $pg = $_GET['pg']; $doespgexist = mysql_num_rows(mysql_query("SELECT * FROM users WHERE id=$pg")); $pgf = mysql_result(mysql_query("SELECT firstname FROM users WHERE id=$pg"),0); $pgl = mysql_result(mysql_query("SELECT lastname FROM users WHERE id=$pg"),0); $dynamicfullname="$fullname"; if (!$pg || $pg==$id || $pg=='' || $doespgexist!=1) header("Location: http://claud.wordsfree.org/"); else{ $ptitle = "Sending friend request..."; $frstatus=checkRelationship($id,$pg); switch($frstatus){ case 0: mysql_query("INSERT INTO relationships VALUES($id,$pg,'n')"); mysql_query("INSERT INTO notifications VALUES(NULL,'$dynamicfullname has sent you a friend request!',NULL,'$pg','n')"); mysql_query("INSERT INTO notifications VALUES(NULL,'You have sent a friend request to $pgf $pgl.',NULL,'$id','n')"); header('Location: ' . $_SERVER['HTTP_REFERER']); break; case 1: echo "You're already friends with that person! Back to claud"; break; case 2: echo "You have already sent a friend request to that person. Back to claud"; break; case 3: mysql_query("UPDATE relationships SET accepted='y' WHERE ida=$pg AND idb=$id"); mysql_query("INSERT INTO notifications VALUES(NULL,'$fullname has just accepted your friend request!',NULL,'$pg','n')"); header('Location: ' . $_SERVER['HTTP_REFERER']); break; } } ?>