Gossamer Forum
Home : Products : DBMan : Installation :

Calculated field

Quote Reply
Calculated field
I will calculate a age field from the entered age group and the actual year. I have made a new sub in html.pl called before_add_record. This sub is called just before the record is stored in the database, this is checked, it works. In this sub (before_add_record) I will do something like this:

$rec{'age'} = $year - $rec{'agegroup'};

The field "age" is never filled in. Can somebody tell me what I have to do that this field will be filled in?

Rene
Quote Reply
Re: Calculated field In reply to
You are most likely dealing with a scope problem. %rec is usually declared with my() which means it is not accessible to any subroutine but the one it is declared in.

I would change it so that you do:

$rec{'age'} = &before_add_record ($rec{'agegroup'});

and then in your sub before_add_record:

sub before_add_record {
# -----------------------------------
my $agegroup = shift;

...

return $age;

}

Hope that helps,

Alex
Quote Reply
Re: Calculated field In reply to
It still not works. Thanks for the input Alex, I think in this place where I call before_add_record is $rec{'agegroup'} not accessible. I call this sub in add_record in db.cgi just after the line

if ($status eq "ok") {

When I check the value in my new sub before_add_record then agegroup is 0 but in the database I have not 0.
Can I call my sub in a other part of the script, or has somebody another idea?

Rene