Buy Now
Sign in

how to get id of last database-insterted record?

seppo , November 06 at 11:44
Answered
S
seppo
Typically, one could use:
$conn = new mysqli($servername, $username, $password, $dbname);
and then later on:
$last_id = $conn->insert_id;
to get the id of last inserted record.
But how to do that with chronoforms, and then use it at next database-insert event?
I quess I could use custom code and write that $last_id = $conn->insert_id, but what to use instead conn, and would it work or is there some DB insert bu chronoforms itself in between?
Also, if I was to use such custom code, how then to get that $last_id to be used with next database save-method?

​Thanks in advance!
GreyHead
Hi seppo,
Why do you need that? If the table is set in MySQL to auto-increment then it will automatically get the next id when you save the record.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
seppo
To use save to database again, for relational purposes: I need to save parts of the form to another table, and set there the id of the first database record, thus to keep them connected.
Also if I could need that information for dynamic form: If I need to reference that already saved part i.e. at another page of multipage form.
healyhatman
It will be available as part of the save data action -> {var:save_data#.id} (if the column is called id, otherwise use whatever your column is called)
Web developer at SkySpider.com.au
I don't work for ChronoEngine but I do accept donations paypal.me/healyhatman
S
seppo
Thank you healyhatman, that was it!