php – Temporarily store form data before writing to database

Question:

How do I temporarily store data from a form before inserting it into the database? I have a form with a set of fields. After the user fills in the set of fields, he will have the option to add one more set with the same fields to enter new values. I would like to do the insertion in the database only when the user finishes filling it out. Each set of fields must be a record in the table. How can I do this?

Answer:

You can create an array in $_SESSION and for each set you add a new index into the array. To do this, look for the size of the array and:

$_SESSION[$tamanho+1]['nome'] = $_POST['nome'];
Scroll to Top