<?php
include("../../includes/connect.php");
print_r($_POST);
echo "<hr />";

    $commentSetName = $_POST['commentSetName'];
    $commentSetLanguage = $_POST['commentSetLanguage'];
    
    $connection->query("INSERT INTO comments_sets (set_name,set_language) VALUES ('$commentSetName','$commentSetLanguage')");
    $questionset = $connection->lastInsertId();
    $domande = $_POST['domande'];


for($d = 0; $d < count($domande); $d++)
{
    $commentText = $domande[$d]['domanda'];
    
    $qdomanda = $connection->prepare("INSERT INTO comments (text,isChildren,parentComment,sets_in) VALUES (?,?,?,?)");
    $qdomanda->execute(["$commentText",0,0,"$questionset"]);
    
    $idComment = $connection->lastInsertId();
    for($r = 0; $r < count($domande[$d]['risposte']); $r++)
    {
        $subCommentText = $domande[$d]['risposte'][$r]['risposta'];
        $qrisposta = $connection->prepare("INSERT INTO comments (text,isChildren,parentComment,sets_in) VALUES (?,?,?,?)");
        $qrisposta->execute(["$subCommentText",1,$idComment,"$questionset"]);
    }
}




?>