Hello Friends,I need your help.I am creating one form which show records on table.I need to insert this records to another db.But,each row will button to add record.After clicking that button only that particular should be added.I need your help guys.

Is this code tossing an error? Security issues aside, nothing is jumping out at me as being wrong

No,the code is correct.As you can see each record row has button name as send which inserts record in another db once clicked.It's inserting records also but only the records of last row.I am trying to insert record of particular row when it's send button is clicked.

The thing is that you have name attributes for your hidden fields the same for every row so the $_POST array contains only teh last row (last assigned name attributes). You should give the name attributes in each row a unique identifier that is linked to the row in a database. An id field would be the best for this but I am not sure whether you have one.

While I was writing this your code miraculously dissapeared so I can not comment further.

Member Avatar

OK think I got it.

Your underlying name and value attributes are key to this working.
For single send with normal form submission, you'll probably depend on the name attribute and the primary key form the first DB table:

<button name="add[]" value="1">AddMe</button>
<button name="add[]" value="2">AddMe</button>
<button name="add[]" value="3">AddMe</button>
<button name="add[]" value="4">AddMe</button>

That can be built from a query loop:

$button = "<button name='add[]' value='{$row['id']}'>AddMe</button>";

For an ajax solution, a similar option could be implemented, which fancy removal of the tablerow when insert was successful.