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

     echo "Creo il nuovo set di domande";
    $questionSetName = $_POST['questionSetName'];
    $questionSetLanguage = $_POST['questionSetLanguage'];
    
    $qInserimento = $connection->prepare("INSERT INTO questions_sets (set_name,set_language) VALUES (?,?)");
    $qInserimento->execute(["$questionSetName","$questionSetLanguage"]);
    $questionSetId = $connection->lastInsertId();
    $domande = $_POST['domande'];


for($d = 0; $d < count($domande); $d++)
{
    $questionText = $domande[$d]['domanda'];
    $qDomanda = $connection->prepare("INSERT INTO questions (language,text,sets_in) VALUES (?,?,?)");
    $qDomanda->execute(["$questionSetLanguage","$questionText","$questionSetId"]);
    
    $idQuestion = $connection->lastInsertId();
    for($r = 0; $r < count($domande[$d]['risposte']); $r++)
    {
        $answerText = $domande[$d]['risposte'][$r]['risposta'];
        $qRisposta = $connection->prepare("INSERT INTO answers (question_id,text,sets_in) VALUES (?,?,?)");
        $qRisposta->execute(["$idQuestion","$answerText","$questionSetId"]);
    }
}




?>