Get last insert ID

Hi Guys,

I was wondering whether someone might be able to give me some direction as to how I’d go about getting the last record inserted ID

Basically I have a form that I will be inserting into a table and once its inserted I’m going to add an action to browser -> go.to pageb.php?id=x (x being the record I’ve just inserted on the form) so that I can repopulate the form on pageb.php for review after some calculations have been done.

Thanks in advance

Ben

Hi Ben,
The inserted Id is available just after the insert step.
Just add a “set value” step in server connect steps, after the insert step, bind the inserted Id as a value and enable the “output” option. Then setvalue step will be available on the front-end.
You can check the docs here, to see how to access the inserted id https://github.com/Wappler/docs/wiki/Get-Inserted-Record-ID

4 Likes

Thank you very much Teodor!

i was determined not to ask this but after several hours of failure to work it out i have to ask.
I am basically trying to do the same as Ben
I have created the insert server action, added a set value to bind to the value of the last id to the variable and checked Output.
How to i access that variable at the app connect front end? it does not seem to appear anywhere. I tried adding an extra server connection (with no auto load to stop it running) but I still cant find the value in any data picker. I am sure the answer is “easy when you know how” but any help appreciated. I promise a video on the topic if i can work it out myself!!

On the front end you will have the data available under the server connect form, when called in the data picker.

We had a bug for bootstrap based Server Connect forms missing the output data in the data picker but it should be now solved in the ver 1.3.0

1 Like

Thanks @George, guess it is a good job i have just installed 1.3.0 so i will try again.
P.S. do you lot ever sleep, you are worse than me!

1 Like

Working perfectly now thanks @George

1 Like

Video as promised.
Insert record then redirect with new ID value

1 Like

Hyperbytes:

Good evening… I really appreciate your tutorials. However, after viewing your tutorial about 5 times, I have a question. Do you have to use an Update action for this to work?

So far, how I am trying to use it isn’t working.

Here’s what I am trying to do. I would like to capture the new ID so that I can use it to filter via URL on the next page. On the next page, I have a detail list that I would like to show only the data that matches that ID that was passed over via URL.

Example: A user fills out the form for their credentials, then click submit and are sent to a review page to verify and make any changes if necessary.

Some reason when I use your tutorial, the result ends up each time with an empty ID in the URL, i.e. page.php?id=

Here’s the line of code:

dmx-on:success=“browser1.goto('general_verify.php?id='serverconnectform1.data.last_id)”

What do you suppose I’m missing?

there is currently a bug in wappler and last insert IDs are returning null. @George is aware

fix here.

Thanks!

It works!

Thanks to the W-team and Brian for your great collaboration.

1 Like

Hi Hyperbytes, I’m following your video step by step but there are problems.
In the data bindings tree (“go to” setup) there is nothing undrer data.
What do you suppose I’m missing?

1 Like

Please update Wappler to 2.7.1 and try again.
Also make sure the Output option for the insert step is enabled in server connect.

Thank you Teodor. First problem fixed.