Gossamer Forum
Home : Products : DBMan : Customization :

Relational question

Quote Reply
Relational question
I am attempting the relational database MOD. My app is the same as the MOD: a user database and an items database. All works well but this: I want to first select a user and then add an item automatically under the selected user's ID.

I have tried the following link which does not work (field UserID exists in both databases):

db_script_url?db=items&uid=$db_uid&addform=1&UserID=$rec{'UserID'}

I see 2 problems:

1. the function $rec{UserID} is returning a null

2. Even when I try to hardwire the link to say ...&UserID=3, it still does not work.

What am I doing wrong.
Quote Reply
Re: [johnww] Relational question In reply to
For your user database do you have the userid setup as the key field?

If so, and that is how it should be for the mod to work correctly, than you would use a link which would include their uid such as:

$db_script_url?db=items&uid=$db_uid&add_form=1

If you want the userid automatically added to the add_form you can make the following changes to your db.cgi file.

In db.cgi, sub get_defaults after:

foreach $field (keys %db_defaults) {
$default{$field} = $db_defaults{$field};

####### add userid in add form #####
($auth_user_field >=0) and ($db_defaults{$db_cols[$auth_user_field]} = $db_userid);
####### end change #######
}

If you don't want the userid automatically filled in if you are logged in as admin use the following instead:

####### add userid in add form ###########
unless ($per_admin) {
($auth_user_field >=0) and ($db_defaults{$db_cols[$auth_user_field]} = $db_userid);
}
####### end change #######
}

You can do the same in sub add_record

after: my ($output, $status, $counter);

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/