Insert Multiple Rows Into MySQL With PHP Using Foreach Arrays
3 min readJul 30, 2020
In this tutorial, we are going to learn how to insert multiple rows into MySQL with PHP using foreach arrays. To insert multiple form data, we need to generate multiple form rows and we will do it by using click function in jquery to generate the rows on clicking the button multiple times, and on the other hand, we will use the remove() function to remove the desired row.
Generating multiple rows on clicking Add new row button using jquery before submitting the form
- When we click add new row button the first time, then we will get the length of the row by using the class of the field ‘SL No’ from the class attribute of SL No field.
- Now, we will increase the length of the rows by adding 1 with parseInt(1) and store in a variable i.
- Now, we will add the next row using the append() function in jquery and use the length variable i with all the remaining fields of the form.
- We will also remove the added rows with the…