Get primary key value of table after DB save

kwok 11 Mar, 2016
Hi Bob,

I have a DB save to a table with 'id' as the primary key.

Right after it I have a custom code that tries to capture the value of that primary key following this guide: https://www.chronoengine.com/faqs/63-cfv4/cfv4-working-with-form-data/2596-how-can-i-give-a-unique-id-to-each-form-submission.html
<?php
$new_id = $form->data['chronoform_data']['cf_id'];

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query = "INSERT INTO.... new_table(id,......) Values('$new_id',....)";

$db->setQuery($query);
$db->execute();
?>


The value of the $new_id is found to be always 0!

Please kindly advise what's wrong with my code?

Thanks,
kwok
GreyHead 11 Mar, 2016
Hi Kwok,

I suggest that you add a Debugger action temporarily after the DB Save - that will show you where the id value is. My guess is that it isn't called cf_id in the table you are updating.

Bob
kwok 11 Mar, 2016
Hi Bob,

I placed the debugger before the DB Save.

Per your advice, I placed the debugger after the DB Save. It shows that the field that contain the value is

$form->data['id']

You are genius!

I always thought that the debugger is able to show all information after its line.

Really appreciate your guidance!

Thanks,
kwok
GreyHead 11 Mar, 2016
Hi kwok,

The Debugger shows the information at the point in the action sequence where it is. Sometimes it's useful to use two at different locations to see what is changing.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger