<?php
$servername = "localhost";
    $username = "root";
    $password = "";
    $database = "raimondsedvins_4110";

// Izveidot savienojumu
    $connection = new mysqli($servername, $username, $password, $database);

    //parbaude
    if ($connection->connect_error) {
      die("Connection failed: " . $connection->connect_error);
    }

// id no pieprasijuma
$inviteId = $_GET['id'];
// atgriez nepieciesamo uzaicinajumu no friend_invites table
$sql = "SELECT * FROM friend_invites WHERE id = $inviteId";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
  $row = $result->fetch_assoc();
  // Ievieto uzzaicinajumu friend_list_data tabula
  $friendName = $row["invites"];
    $insertSql = "INSERT INTO friend_list_data (friends) VALUES ('$friendName')";
     $insertResult = $connection->query($insertSql);
  if ($insertResult === TRUE) {
    // izdzes ierakstu no  friend_invites tabulas
    $deleteSql = "DELETE FROM friend_invites WHERE id = $inviteId";
    $deleteResult = $connection->query($deleteSql);

    if ($deleteResult === TRUE) {
      echo "Invite accepted successfully.";
    } else {
      echo "Error deleting invite: " . $connection->error;
    }
  } else {
    echo "Error inserting invite into friend list: " . $connection->error;
  }
} else {
  echo "Invite not found.";
}
$connection->close();
?>

