I have created a table. There are dynamic text field for each row to fill the information. I know how to create and dynamic text field. But i am having a doubt in how to add them into database by clicking a submit button. In this picture you can get the idea. By clicking that add link we can add dynamic text field as we need. when i click submit all data are saved into same name(ex: saving in tr).
-
Use an array in the `name` attribute of your fields. That way all data will be send to your server. No matter how many fields you add dynamicly: Example: `name="mydata[]"` – icecub Nov 29 '16 at 07:46
-
yhh but i have to get like name by name. for example if row 1 have dynamic field then it save row 1's name. row 2 will save in row's name. but here row1, row 2 both save in row 1's name. i couldn't define those dynamic field to each row. so now i am trying that – k.MK28 Nov 29 '16 at 08:26
2 Answers
Your field name should be array type.
Example [Row 1]
<input type="text" name="name[]" />
<select name="types[]">
<option>....</option>
<option>....</option>
</select>
Example [Row 2]
<input type="text" name="name[]" />
<select name="types[]">
<option>....</option>
<option>....</option>
</select>
Note : Follow above code for every rows.
After submitting form data, PHP
array looks like.
array(2) {
["name"]=>
array(2) {
[0]=>"Name 1"
[1]=>"Name 2"
}
["types"]=>
array(2) {
[0]=>"Type 1"
[1]=>"Type 2"
}
}
Use PHP
loop and separate every rows for saving data to your database.

- 2,707
- 1
- 23
- 36
-
thank you for your reply but the think is those rows also dynamic. i am getting that name from database. if database have 2 name then it will be two row. i am having a loop also but still i couldn't define those dynamic field to each row. so now i am trying that – k.MK28 Nov 29 '16 at 08:22
-
But, You can put dynamic field in `name="{DYNAMIC_NAME_HERE}"` from database. @k.MK28 – Sumon Sarker Nov 29 '16 at 08:51
-
i mean name from data base is---- in that pic there are some name like tr, uit those are from database. – k.MK28 Nov 29 '16 at 08:58
-
But in your question those are not `name`, Those are `value` @k.MK28 – Sumon Sarker Nov 29 '16 at 09:07
-
-
So, You can put those `value` in `input` fields like as `value=""` using loop @k.MK28 – Sumon Sarker Nov 29 '16 at 09:30
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129333/discussion-between-k-mk28-and-sumon-sarker). – k.MK28 Nov 29 '16 at 09:47
you should use a software like phpmyadmin and create a database there. once created, name a table for example 'mytable' and add the necessary columns corresponding to your data. so when you press the submit button, it should take action on a separate php file which would use POST method to take the values and contain them in a variable. once in a variable create an sql statement like this one "INSERT INTO mytable .............. " with ....... being your values. its a long process though, you should use a website to learn how to insert data into your database

- 13
- 7
-
thank you for your reply i know those things , i couldn't handle with dynamic text fields, the think is those rows also dynamic. i am getting that name from database. if database have 2 name then it will be two row. i am having a loop also but still i couldn't define those dynamic field to each row. so now i am trying that – k.MK28 Nov 29 '16 at 08:23
-
[link](http://stackoverflow.com/questions/66385/dynamic-database-schema) – Faizan Ali Nov 29 '16 at 08:42
-