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
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