Multiple Tables Problem

postmanpatscat 29 Nov, 2011
Hi,

So far I have been successful in getting a form to load data from table 1, based on a token and display that on the form.

The next step is to, on submit, change a value in table 1 and write a new data row to table 2.

I have created two db saves pointing to the correct tables, and a hidden box as per the tutorials containing the cf_id of the row in table 1(both db saves have different model_ids.)

On submit, data is changed in table 1 but nothing written to table 2.

I have tried the fix detailed here to no avail: http://chronoengine.com/forums.html?cont=posts&p=104173#p104173

Any help would be much apprectiated.
GreyHead 29 Nov, 2011
Hi postmanpatscat,

There isn't enough info here to know what is happening. You can try adding a debugger action to the form or, possibly more usefully, temporarily turn on Site Debug and see what is in the MySQL queries shown then.

Bob
postmanpatscat 29 Nov, 2011
Thanks for the quick response!

After trawling through the debug info I think the problem is because the primary key for both is cf_id. Table 2 is using the cf_id loaded from table 1 and trys to write to that row rather than creating a new instance everytime.

Here is the debug (first query is working fine but second one shouldn't be an update or have WHERE cf_id=1):
UPDATE `Table1`
SET `cf_modified`='2011-11-30 09:45:14',`date`='2009-11-13'
WHERE cf_id='1'

UPDATE `table2`
SET `cf_modified`='2011-11-30 09:45:14',`date`='2009-11-13',`yes`='1',`comments`='aaaaaaaaaaaaaaaaa',`input_submit_6`='Submit',`number`='1'
WHERE cf_id='1'

Any suggestions?
postmanpatscat 29 Nov, 2011
Simply changing the name of cf_id to sf_id in table2 had the desired effect.

Problem solved thanks.
GreyHead 30 Nov, 2011
Hi postmanpatscat ,

Well found :-)

An alternative wodul be to use a Model ID for one or the other to separate out the variable groups. To do this you'd need to move the data into a $form->data['some_model_id'] array.

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