<?php
    include('db.php');

    if (isset($_POST['ifNew'])){
        
        //set up data
        $ifNew = $_POST['ifNew'];
        $userId = $_POST['userId'];
        $documentId = $_POST['documentId'];

        if ($ifNew == 1){
            //insert data
            $sql = "INSERT INTO favourite (userId, documentId) VALUES ('$userId', '$documentId')";
            $insert = $mysqli->query($sql);
        }
        else if ($ifNew == 0){
            //insert data
            $sql = "DELETE FROM favourite WHERE userId = '$userId' AND documentId = '$documentId'";
            $insert = $mysqli->query($sql);
        }
    }



?>