Good day everyone!
Basically, my JavaScript knowledge was enough to make a code, which returns a JSON.stringify'ed array to PHP backend using Ajax in this form:
["Test questionnaire.",{"type":"textQuestion","name":"How are you doing?"},{"type":"mapQuestion","name":"Show your favorite location:"},{"type":"selectQuestion","name":"Which one of them is your favorite?","options":["First","second","third"]}]
As you can see, there is a bunch of objects. First one (test questionnaire). Goes into table "questionnaires". Then come the questions. They are connected with foreign key to questionnaires_id and must be added to database as question_type and question_name. If type is selectQuestion, then it also adds the "options" to options table and connects them to related question in questions table.
I understand, that I have to use json_decode to separate the values, i don't understand how to create new rows in mysql database and automatically connect child (question) to parent (questionnaire).
Thank you in advance!