I want to use mysqli_insert_id() to get the last ID that generated by my save data action, but I'm not sure how use it in CFv6.
What should I use for the connection for this function?
What should I use for the connection for this function?
Hi omidhz,
Please try adding a Debugger action - ChronoForms usually adds the record ID to the form data for you.
Bob
Please try adding a Debugger action - ChronoForms usually adds the record ID to the form data for you.
Bob
Here the result my debugger:
Array
(
[option] => com_chronoforms6
[chronoform] => relationship
[event] => submit
[button] => other_hs
[Itemid] =>
)
Array
(
[save_data5] => Array
(
[data] => Array
(
[option] => com_chronoforms6
[chronoform] => relationship
[event] => submit
[button] => other_hs
[Itemid] =>
[parentID] => 0
)
[_success] => Data saved successfully
[log] => Array
(
[0] => INSERT INTO `hs_relationship` (`parentID`) values ('0');
)
[var] => Array
(
[parentID] => 0
[id] => 52
)
)
)
I'm not sure if I was clear on my question. Here is more details.
I have a form, that submits data to relationship table. Relationship table, has a primary key, AUTOINCREMENT which is called ID
Now, what I need is, after user submits information to the relationship table, I need to get the newly generated ID and pass that to my next table to be saved as relationshipID.
My goal is to use the ID in relationship table and relationshipID in my second table to link the data as one-to-one relationship.
I was thinking that I could use mysqli_insert_id() to obtain the last ID created, but I'm not sure how to use it.
I really appreciate your help in advance.
I have a form, that submits data to relationship table. Relationship table, has a primary key, AUTOINCREMENT which is called ID
Now, what I need is, after user submits information to the relationship table, I need to get the newly generated ID and pass that to my next table to be saved as relationshipID.
My goal is to use the ID in relationship table and relationshipID in my second table to link the data as one-to-one relationship.
I was thinking that I could use mysqli_insert_id() to obtain the last ID created, but I'm not sure how to use it.
I really appreciate your help in advance.
Hi omidhz,
It looks from the Debugger as though the id should be in $this->data['save_data5']['var']['id'] - there may be some other syntax for getting it but I don't know what that would be.
Bob
It looks from the Debugger as though the id should be in $this->data['save_data5']['var']['id'] - there may be some other syntax for getting it but I don't know what that would be.
Bob
I'm not sure if I'm doing something wrong, but when I add the following in a custom php code
I get this error:
echo $this->data['save_data5']['var']['id'];
I get this error:
Notice: Undefined index: save_data5 in C:\xampp\htdocs\joomla\libraries\cegcore2\admin\extensions\chronofc\functions\php\php_output.php(6) : eval()'d code on line 1
Hi vales,
Thank you for your help. That format Is working perfectly and returning the ID generated by the form.
But I have a question, if multiple users click on submit button at the same time from different computers, will this code be appropriate to use to retrieve the ID created by the user without mixing them up between different users?
I was reading about a MySQL function LAST_INSERT_ID that can do this, but not sure how I can use that with this form. Do I need to use this function to make sure I get the correct ID, or just using the variable you suggested is accurate and will work?
Thanks again for your help.
Thank you for your help. That format Is working perfectly and returning the ID generated by the form.
But I have a question, if multiple users click on submit button at the same time from different computers, will this code be appropriate to use to retrieve the ID created by the user without mixing them up between different users?
I was reading about a MySQL function LAST_INSERT_ID that can do this, but not sure how I can use that with this form. Do I need to use this function to make sure I get the correct ID, or just using the variable you suggested is accurate and will work?
Thanks again for your help.
Hi omidhz,
This value is the ID of the record that has just been created by the form - unlike LAST_INSERT_ID it is not going to be affected by multiple submissions at the same time.
Bob
This value is the ID of the record that has just been created by the form - unlike LAST_INSERT_ID it is not going to be affected by multiple submissions at the same time.
Bob
This topic is locked and no more replies can be posted.