A unf. social network done poorly.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.7KB

  1. <?php // Send friend request
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/session.php');
  5. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/config.php');
  6. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/user-data.php');
  7. /*
  8. This could be good. May need to change it up in the future. I'm very concerned about scaling. -- Ashton
  9. */
  10. $connection = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName);
  11. $profile_id_request = (!empty($_POST['profile_id'])) ? $_POST['profile_id'] : false; // Grabs the requesters' ID.
  12. $remove = (!empty($_POST['remove'])) ? $_POST['remove'] : false;
  13. $profile_id_friend_request = mysqli_real_escape_string($connection, $profile_id_request); // simple security.
  14. $remove = mysqli_real_escape_string($connection, $remove);
  15. $numberOne = 1; // hmh. Not really needed, but variables.
  16. if($remove){ // Remove friend.
  17. if($profile_id_friend_request){
  18. $remove_friend = "DELETE FROM friends
  19. WHERE user_one='$user_id' AND user_two='$profile_id_friend_request'
  20. OR user_one='$profile_id_friend_request' AND user_two='$user_id'";
  21. if(!mysqli_query($connection, $remove_friend)){
  22. die("err... You aren't friends.");
  23. }
  24. echo "DELETED THIS MOTHERFUCKER. GG";
  25. }
  26. }
  27. if($remove == false){ // Add friend.
  28. if($profile_id_friend_request){
  29. $send_friend_request = "INSERT INTO friends(user_one, user_two, pending)
  30. VALUES
  31. ('$user_id','$profile_id_friend_request','$numberOne')";
  32. if(!mysqli_query($connection, $send_friend_request)){
  33. die("You are already friends.");
  34. }
  35. echo "Friend request sent.";
  36. }
  37. }
  38. ?>