i'm pulling my hair out! i have the following code in db.cgi:
#-----------------------------------------------------
$cols2 = 'Lock,Userid,DBA,Firstname,Lastname,Address,City,State,Zip,Phone_home,Phone_cell,Phone_ofc,Email_address,URL,Media,Month_expires,Display,Publicity,Membership,Events,Hospitality,Website,Gallery,Newsletter,Category,KAZ_web,Web_gallery';
@db2_cols = split /,/,$cols2;
$db2_file_name = $db_script_path . "/members.db";
$db2_key_pos = 1;
}
sub get_record2 {
# --------------------------------------------------------
# Given an ID as input, get_record returns a hash of the
# requested record or undefined if not found.
my ($key2, $found, $line, @data, $field, $restricted);
$key2 = $_[0];
$found = 0;
# spambuster hack delicia comment next line
# ($restricted = 1) if ($auth_modify_own and !$per_admin);
open (DB, "<$db2_file_name") or &cgierr("error in get_records. unable to open db file: $db2_file_name.\nReason: $!");
flock(DB, 1);
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@data = &split_decode2($line);
#next LINE if ($restricted and ($db_userid ne $data[$auth_user_field]));
if ($data[$db2_key_pos] eq $key2) {
$found = 1;
for ($j = 0; $j <= $#db2_cols; $j++) { # Map the array columns to a hash.
$rec2{$db2_cols[$j]} = $data[$j];
}
last LINE;
}
}
close DB;
$found ?
(return %rec2) :
(return 'undef');
}
##########################################################
sub split_decode2 {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($j = 0; $j <= $#array; $j++) {
$array[$j] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$j] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}
in html_record_form for my exhibit database, i have the following:
if ($in{'add_form'} || $in{'add_duplicate'}) {
if ($in{'Userid'}) {
$rec{'Userid'} = $in{'Userid'};
}
if ($rec{'Userid'}) {
&switch_to_member;
%rec2 = &get_record2($rec{'Userid'});
foreach $col (@db_cols) {
if ($rec2{$col}) { $rec{$col} = $rec2{$col}; }
}
}
}
then it populates my form with the values just fine. working great!
now the problem. in another database i have the following code in html_record:
$rec{'Userid'} =~ s/<.?B>//g;
&switch_to_member;
%rec2 = &get_record2($rec{'Userid'});
print qq|$rec{'Userid'} $rec2{'Firstname'} </td><td valign="top">$rec{'Email_address'}|;
it doesn't work. it does not show Firstname. the only field in common between these two databases is userid. i can't figure out why it works fine in html_record_form for one db but doesn't work in html_record for the other. i tried inserting undef %in; but then i lost my instant mod/delete buttons. what am i missing???
Code:
sub switch_to_member { #-----------------------------------------------------
$cols2 = 'Lock,Userid,DBA,Firstname,Lastname,Address,City,State,Zip,Phone_home,Phone_cell,Phone_ofc,Email_address,URL,Media,Month_expires,Display,Publicity,Membership,Events,Hospitality,Website,Gallery,Newsletter,Category,KAZ_web,Web_gallery';
@db2_cols = split /,/,$cols2;
$db2_file_name = $db_script_path . "/members.db";
$db2_key_pos = 1;
}
sub get_record2 {
# --------------------------------------------------------
# Given an ID as input, get_record returns a hash of the
# requested record or undefined if not found.
my ($key2, $found, $line, @data, $field, $restricted);
$key2 = $_[0];
$found = 0;
# spambuster hack delicia comment next line
# ($restricted = 1) if ($auth_modify_own and !$per_admin);
open (DB, "<$db2_file_name") or &cgierr("error in get_records. unable to open db file: $db2_file_name.\nReason: $!");
flock(DB, 1);
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@data = &split_decode2($line);
#next LINE if ($restricted and ($db_userid ne $data[$auth_user_field]));
if ($data[$db2_key_pos] eq $key2) {
$found = 1;
for ($j = 0; $j <= $#db2_cols; $j++) { # Map the array columns to a hash.
$rec2{$db2_cols[$j]} = $data[$j];
}
last LINE;
}
}
close DB;
$found ?
(return %rec2) :
(return 'undef');
}
##########################################################
sub split_decode2 {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($j = 0; $j <= $#array; $j++) {
$array[$j] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$j] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}
in html_record_form for my exhibit database, i have the following:
if ($in{'add_form'} || $in{'add_duplicate'}) {
if ($in{'Userid'}) {
$rec{'Userid'} = $in{'Userid'};
}
if ($rec{'Userid'}) {
&switch_to_member;
%rec2 = &get_record2($rec{'Userid'});
foreach $col (@db_cols) {
if ($rec2{$col}) { $rec{$col} = $rec2{$col}; }
}
}
}
then it populates my form with the values just fine. working great!
now the problem. in another database i have the following code in html_record:
$rec{'Userid'} =~ s/<.?B>//g;
&switch_to_member;
%rec2 = &get_record2($rec{'Userid'});
print qq|$rec{'Userid'} $rec2{'Firstname'} </td><td valign="top">$rec{'Email_address'}|;
it doesn't work. it does not show Firstname. the only field in common between these two databases is userid. i can't figure out why it works fine in html_record_form for one db but doesn't work in html_record for the other. i tried inserting undef %in; but then i lost my instant mod/delete buttons. what am i missing???