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

    $questionSetName = $_POST['questionSetName'];
    $questionSetLanguage = $_POST['questionSetLanguage'];
    
    $connection->query("INSERT INTO profilation_sets (set_name,set_language) VALUES ('$questionSetName','$questionSetLanguage')");
    $questionset = $connection->lastInsertId();
    $domande = $_POST['domande'];


for($d = 0; $d < count($domande); $d++)
{
    $questionText = $domande[$d]['domanda'];
    if($questionText != "")
    {
    
    $qDomanda = $connection->prepare("INSERT INTO profilation_questions (language,text,sets_in) VALUES (?,?,?)");
    $qDomanda->execute(["$questionSetLanguage","$questionText","$questionset"]);
    

    $idQuestion = $connection->lastInsertId();
    for($r = 0; $r < count($domande[$d]['risposte']); $r++)
    {
        $answerText = $domande[$d]['risposte'][$r]['risposta'];
        if($answerText != "")
        {
            $qRisposta = $connection->prepare("INSERT INTO profilation_answers (question_id,text,sets_in) VALUES (?,?,?)");
            $qRisposta->execute(["$idQuestion","$answerText","$questionset"]);
        }
    }
    }
}




?>