Hi,
I am a beginner PHP student trying to tackle a personal project right now.
My initial problem was this. Let’s say there is a set of field for the user to fill in.
Field1 field1 field3 field4 field5
I first wanted that if those fields are filled or if the user wanted an additional set of field by clicking a button, a new blank set of field would pop. I found out with the incorporation of AJAX and HTML DOM I can accomplish that.
My problem is how do I insert this indefinite numbers of set of fields into mysql?
By the time the user clicks ‘submit’ and all the forms are validated, I do not know how many sets of field were made. So the conventional way of
‘INSERT INTO tables () values ();’
wouldn’t work since it will only INSERT the first set of values.
So how do I make sure that no matter how many sets of fields are filled in, I will be able to INSERT all of them into MYSQL?
My vague solution would be
1. For each set of fields, give them a unique ID added to their name such as 1, 2, 3, 4, 5 or insert each set of fields into an array such as array1, array2, array3.2. Then later loop them and insert them into mysql.
Am I in the right direction? If I’m not could someone tell me at least some keywords that I could google to help me out? If you could give me some short snippets, that would even more amazing.
ANyways, thank you so much for reading this rather long post and have a great evening guys.