Gossamer Forum
Home : Products : DBMan : Customization :

Build Select Field from External DB problem

Quote Reply
Build Select Field from External DB problem
I have a relational database system with two kinds of users (user and artist). Each user has their own signup form with their account information. In addition I also have a form that a user would complete to request an appt with the second type of user (item). On the request form I have included a field that is built from the artist.db and the Name field...but when I try to use the form to add a record it gives me an "Name (Can not be left blank)" error and I am not sure why.

My database is setup like this:

user.cgi
user.cfg
user_html.pl
user.db
user.count
item.cfg (shares user.cgi)
item_html.pl
item.db
item.count
artist.cgi
artist.cfg
artist_html.pl
artist.db
artist.count
default.pass
default.log

In the item.cfg file the fields are as follows:

# Definition of your database. Format is
# field_name => ['position', 'field_type', 'form-length', 'maxlength', 'not_null', 'default', 'valid_expr']
%db_def = (
'UserID' => [ 0, 'alpha', -1, 255, 1, '', ''],
'ItemID' => [ 1, 'alpha', -1, 255, 1, '', ''],
'Name' => [ 2, 'alpha', 0, 255, 1, '', ''],
'ArtistOffer' => [ 3, 'numer', 20, 255, 0, '', ''],
'EventDate' => [ 4, 'date', 20, 255, 1, &get_date(), ''],
'EventTitle' => [ 5, 'alpha', 20, 255, 0, '', ''],
'PerformanceTime' => [ 6, 'alpha', 20, 255, 0, '', ''],
'PerformanceLength' => [ 7, 'alpha', 20, 255, 0, '', ''],
'OtherArtists' => [ 8, 'alpha', 20, 255, 0, '', ''],
'EventDescription' => [ 9, 'alpha', '40x5', 1000, 1, '', ''],
'VenueName' => [10, 'alpha', 20, 255, 1, '', ''],
'VenueAddress' => [11, 'alpha', 20, 255, 0, '', ''],
'VenueCityProvince' => [12, 'alpha', 20, 255, 1, '', ''],
'VenueStateRegion' => [13, 'alpha', 20, 255, 1, '', ''],
'VenueCountry' => [14, 'alpha', 20, 255, 0, '', ''],
'VenueZipCode' => [15, 'alpha', 20, 255, 0, '', ''],
'VenueTelephone' => [16, 'alpha', 20, 255, 1, '', ''],
'Website' => [17, 'alpha', 20, 255, 0, '', '^http://'],
'PastAgents' => [18, 'alpha', '40x5', 1000, 1, '', ''],
'PastArtists' => [19, 'alpha', '40x5', 1000, 1, '', ''],
'Status' => [20, 'alpha', -1, 255, 1, 'Pending', '']
);

# The column name for the database key. Can be any column, but it must be unique!
# You can't have two records with the same key value!
$db_key = 'ItemID';
# Track the key? Should DBMan keep a counter of the next key to use? This isn't
# neccessary if you can guarantee that your entry in the key field will be unique
# (i.e. a userid).
$db_key_track = 1;
# Database delimeter.
$db_delim = '|';
# Use file locking (1 = Yes, 0 = No). Should be used, but won't work on Win95.
$db_use_flock = 1;
# Auto generate the html forms (1 = Yes, 0 = No).
$db_auto_generate = 1;
# Display Benchmarking Information (1 = Yes, 0 = No).
# use Benchmark; # Uncomment this line if benchmarking is used.
$db_benchmark = 0;
# Display Debugging Information (1 = Yes, 0 = No).
$db_debug = 0;
# Field number of the "Name" field in the other database
$other_fieldnum = 14;
# Select fields. Field name => 'comma seperated list of drop down options'.
%db_select_fields = (
);

# Radio fields. Field name => comma seperated list of radio buttons.
%db_radio_fields = (
'Status' => 'Pending,Approved,Rejected'
);
# Checkbox fields. Field name => Checkbox value.
%db_checkbox_fields = (
);

And in the user.cgi file I added the following subroutine:

sub build_select_field_from_other_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ($column, $value) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0;
open (DB, "<$db_other_file_name") or &cgierr("unable to open $db_other_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$other_fieldnum], @selectfields)) {
push (@selectfields, $fields[$other_fieldnum]);
}
}
close DB;
$output = qq|<SELECT NAME="$name"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}

Can anyone tell me what I might be doing wrong?
Cher
Quote Reply
Re: [chronisca] Build Select Field from External DB problem In reply to
Are the names appearing for selection in the item db form?

Have you defined the other database in your .cfg file:

# Full Path and File name of the other database file.
$db_other_file_name = $db_script_path . "/other.db";


Is the field name the same in both databases?

Are there any spaces in the contents of the "Name" field?

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Build Select Field from External DB problem In reply to
I did define the database name:
# Full Path and File name of the other database file.
$db_other_file_name = $db_script_path . "/artist.db";

The field name in both databases is: Name

For the "Name" field...there is a space...the artist's name is Robbie Rivera.

Do you think that's the problem? If so, is there a way around this because people are going to most likely want to use a first and last name with a space between them. Not all artists have a one word name.
Cher
Quote Reply
Re: [chronisca] Build Select Field from External DB problem In reply to
Check out this thread for the solution:

http://www.gossamer-threads.com/...gforum.cgi?post=4135

Importing one field from another db
nightowl
17-Aug-1999

Unoffical DBMan FAQ

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