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.
SQL IN HOOK
Re: SQL IN HOOK
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);
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);
Bert
I am using Appgini 5.75
I am using Appgini 5.75
Re: SQL IN HOOK
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.
/Giuseppe
Professional Outsourcing Services
Professional Outsourcing Services