Buy Now
Sign in

how to get id of last database-insterted record?

seppo , November 06 2018
seppo 85
November 06 2018 #381317
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 63.3
November 06 2018 #381322
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.
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
seppo 85
November 06 2018 #381330
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 5.1
November 06 2018 #381331
It will be available as part of the save data action -> {} (if the column is called id, otherwise use whatever your column is called)
Web developer at
I don't work for ChronoEngine but I do accept donations

You can now copy+paste code from forums
seppo 85
November 07 2018 #381340
Thank you healyhatman, that was it!