Skip to content
Advertisement

Storing multi rows from php to sql

When i send post from php to save input values in seperate rows i’m ending with that in ma table always is stored extra blank rows. For example this is the form from which i send post to save values:

And this is where i receive data and insert into db, it insert all products that was in order but it also save extra empty rows.

Advertisement

Answer

Because there are other values in your $_POST array than the ones you want to insert into your table, you are iterating too many times through your foreach loop. Change the loop to iterate over one of the values you have multiple copies of instead e.g. ucenik:

Note you will need to remove the $i = 0; and $i++; lines from your code.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement