1

I have two html forms to register products in an RMA. The first form is really basic and I can easily store the data to the db. The problem comes when I use $newrmaid = $conn->insert_id;(where $conn is a mysqli-object) to get the auto-incremented ID from the db when i insert the data from the first form.

In the second form I need information from the db related to the key in $newrmaid. I got it to work with a set number of products (combine the two forms), but the RMA can have a dynamic number of products attatched to it.

The idea is that when you register a new RMA you get presented a new page with all products that are attatched to this RMA plus a form for attatching new products. When you insert a new product the page refreshes and you can choose to insert more products.

Any good advice?

Anders
  • 11
  • 1
  • You have several ways how to pass the RMA id to the next page. You can either store it in user session, or you can pass it with URL something like ?rmaid=123 or you can link it with the user that has created the RMA and get user id from the session and let him pick which RMA he/she wants to edit – Richard May 26 '16 at 13:00

1 Answers1

0

I'm not the fan of sending back the inserted_id to the next page. Because it could be different when more than one user are inserting data at the same time.

Retrieve it before loading the form

SELECT id FROM table ORDER BY id DESC LIMIT 0,1
Mojtaba
  • 4,852
  • 5
  • 21
  • 38