The following code is supposed to take information provided by a form and add it to the database. Not only that, but theres a small section that's supposed to take the data from a certain field (Callsign) and add "-Y" if the data from another field says yes or no.
##########################################################
## Joining ##
##########################################################
sub join_create {
# --------------------------------------------------------
# Adds the new member's record into the validation wating
# pool, E-mails an "auto-respone" to the member, and then,
# E-mails the staff officer a message telling him to come
# validate the new member. Also does some variable
# checking and editing.
my ($output, $status, $counter);
# Set the userid to the logged in user.
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);
(!$per_admin) and ($in{$db_validated_field} = "No");
# First we validate the record to make sure the addition is ok.
$status = &validate_record;
# We keep checking for the next available key, or until we've tried 50 times
# after which we give up.
while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);
$in{$db_key}++;
$status = &validate_record;
}
if ($status eq "ok") {
# Creates a randomly created Callsign, then adds "-Y" to
# the end if SATYTH = "Yes", otherwise, it leaves it
# alone.
@chars = (A .. Z, 0 .. 9);
$random_number = int(rand(9) + 27);
$random_char = int(rand(36));
$random_char2 = int(rand(36));
$Callsign = 'WBK' . $chars[$random_number] . $chars[$random_char] . $chars[$random_char2];
if ( $rec{'SATYTH'} eq 'Yes' ) {
$Callsign = $Callsign . "-Y"
}
else {
$rec{'Callsign'} = $rec{'Callsign'}
}
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB &join_encode(%in);
close DB; # automatically removes file lock
if ($db_key_track) {
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_join_success;
}
else {
&html_join_failure($status);
}
}
The problem is that none of the code in red does anything - if your logged in as WBK73G or default or imadummie, it always puts the value of $rec{'Callsign'} of who you are logged in as and not the randomly generated string.
Any ideas?
Thanks,
Michael DeLong
Code:
##########################################################
## Joining ##
##########################################################
sub join_create {
# --------------------------------------------------------
# Adds the new member's record into the validation wating
# pool, E-mails an "auto-respone" to the member, and then,
# E-mails the staff officer a message telling him to come
# validate the new member. Also does some variable
# checking and editing.
my ($output, $status, $counter);
# Set the userid to the logged in user.
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);
(!$per_admin) and ($in{$db_validated_field} = "No");
# First we validate the record to make sure the addition is ok.
$status = &validate_record;
# We keep checking for the next available key, or until we've tried 50 times
# after which we give up.
while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);
$in{$db_key}++;
$status = &validate_record;
}
if ($status eq "ok") {
# Creates a randomly created Callsign, then adds "-Y" to
# the end if SATYTH = "Yes", otherwise, it leaves it
# alone.
@chars = (A .. Z, 0 .. 9);
$random_number = int(rand(9) + 27);
$random_char = int(rand(36));
$random_char2 = int(rand(36));
$Callsign = 'WBK' . $chars[$random_number] . $chars[$random_char] . $chars[$random_char2];
if ( $rec{'SATYTH'} eq 'Yes' ) {
$Callsign = $Callsign . "-Y"
}
else {
$rec{'Callsign'} = $rec{'Callsign'}
}
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB &join_encode(%in);
close DB; # automatically removes file lock
if ($db_key_track) {
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_join_success;
}
else {
&html_join_failure($status);
}
}
Any ideas?
Thanks,
Michael DeLong