Page 1 of 1

SQL IN HOOK

Posted: 2016-12-12 13:51
by igimanigi
I am new to appgini but I am a programmer. I have a Billig_Header table and a Billing_Detail table. I want to update a 'Total' field in the header table as i add or update the Amount field in the Detail table. After doing some reading, I have done the following in the after_update and after_insert hooks of the Billing_Detail table but its not working.

sql("UPDATE Billing_Header SET Total=Total+{$data['Amount']} WHERE ID={$data['Billing_ID']}");

What am I doing wrong.
Thanks in advance.

Re: SQL IN HOOK

Posted: 2016-12-13 16:38
by Bertv
Hi,
you forgot the return parameter of the sql-(AppGini)function.

What I always do is split the creation of the sql-string and the execution. After the create of the sql-string I can debug it.
With your update this looks
$sql_string = "UPDATE Billing_Header SET Total=Total+{$data['Amount']} WHERE ID={$data['Billing_ID']}";
$result = sql($sql_string, $eo);

Re: SQL IN HOOK

Posted: 2016-12-14 10:54
by igimanigi
oh, thanks. it works now.

Re: SQL IN HOOK

Posted: 2016-12-14 15:08
by DevGiu
Just to clarify, second parameter of sql() function, is not the return parameter, is an "options" parameter., and is optional, throwing a warning on error log, not sure why this affected your query. If you pass array('silent-errors', true), it ignores any possible errors on screen.