hi guys, simply, i have a form that has internal ID auto incremant - mysql - all works ok, i want to display a control page with the fields that was entered... I could show all fields ok onAfterInsert sc_redir to control application with global variables... but the ID is going as "0" it should go normal as the record is created actually in the database, why I can't show it onAfterInsert event so the user knows his record id number is XXX ? I wounder if it is a bug or there is a trick we must follow?
Announcement
Collapse
No announcement yet.
how to print the record id on control application directlyAFterInsert!?
Collapse
X
-
hi sir
but i want to redirect to control application so to give the record ID that was created by entry and also want to add some links to user for where to go next
the id is not yet created when first adding the values of the form, but it supposed to be created when AfterInsert hence we are supposed to be able to show the record id when redirecting after the record is added to db, i just don't understand, i was reading in the forums that should reserve the id or use sequence but couldn't really understand about sequence or how to reserve ID or how to show it after the insert in a control application, still dull to me
Comment
-
I know its punishment bossyet i have to add in that control applications many different links and stuff
but the id still not going correct, i have other data from the same record like name, class, category... all goes ok with sc_redir as parameters but the id is going as "0" showing in the control like id: 0 and name OK class OK category OK..etc.
i use the same form in edit mode and it sends the id number ok to control (onAfterUpdate event)... only in case of first creation of the record (insert) it sends the id: 0, so i thought it is not created yet in the database in onAfterInsert? but obviously it does, and the record is added to db, so the onAfterInsert event should send the id that was created by auto increment and show to user along with the other values!
strange
any hint?
Comment
-
Milke,
If you are using MySQL, you can do like this in AfterInsert:
Code:sc_commit_trans(); sc_lookup(sc,"SELECT LAST_INSERT_ID()"); sc_redir(control_app,new_id=$sc[0][0]);
If you are not using MySQL, then your database of choice should have something similar.
Dave
Comment
-
Hi steph07
it is the same as above
look at the code examples that comes with SC right panel, insert on another table, and add this value to the array [id] to be added to your another table, or even you can set {sc[0][0]} directly, it will send to your another table accordingly
Code:sc_commit_trans(); sc_lookup(sc,"SELECT LAST_INSERT_ID()"); [id]={sc[0][0]};
Comment
Comment