0

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.

Edited by codingweb: Done!

4
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by diafol
0

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.

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.