sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

My database doesn't seem to be storing any of the data I toss at it, at run time all it displays is the $dbm{$_} of the current data you just added to it.

Near the bottom of the script I am trying to print out all the database information but it doesn't seem to hold anything. Any suggestions would be helpful.

#!/usr/bin/perl -w use strict; use CGI; use POSIX; my $query = CGI->new; my %form = %{$query->Vars}; require SDBM_File; my %dbm; my $dbm_file = "evs.dbm"; my $accountID = $query->url_param('accountID'); my $accountAD = $query->url_param('accountAD'); tie %dbm, 'SDBM_File', $dbm_file, O_CREAT|O_RDWR, 0644; use CGI qw/:standard/; print header, start_html('EVS'), start_form, "What's your email address? ",textfield('usermail'),p, submit, end_form, hr; chomp $form{"usermail"}; my $chars; my $adminmail = "admin\@test.com"; my $sendmail = "/usr/lib/sendmail"; my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & * ) ); my $ID; if ($form{'usermail'}) { my @unverified_emails=($form{'usermail'}, $ID); $dbm{'notverified'}=join ",",@unverified_emails; #foreach my $mail (split /,/, $dbm{'notverified'}) { # print "$mail is not verified!\n"; #} do { $ID = join '', map { $chars[ rand @chars ] } 1..17; } while grep {$_ eq $ID} my @used; print "An email has been sent to $form{'usermail'}. Please ch +eck it to verify your information.\n"; ### email the users my $accountAD = "$form{'usermail'}"; my $accountID = $ID; open (MAIL, "|$sendmail -t") or die "Cannot access mail"; print MAIL "To: $form{'usermail'}\n"; print MAIL "From: $adminmail\n"; print MAIL "Subject: Verify your Email Address\n\n"; print MAIL "http://sulfericacid.perlmonk.org/evs/evs.pl?accountID=$a +ccountID&accountAD=$accountAD\n"; close (MAIL); } if ($accountID && $accountAD) { &params; } sub params { if ($accountID && ($accountAD ne '') && (exists $dbm{'notverified'})) +{ $dbm{'verified'} = "$accountAD"; print "Your address has been indexed!\n"; foreach (sort keys(%dbm)) { print "$_ => $dbm{$_}\n"; } } else { print "Your email address and registration did not match. Please ch +eck your email again.\n"; } }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Database not storing data
by rdfield (Priest) on Feb 13, 2003 at 09:56 UTC
    Shouldn't
    $dbm{'verified'} = "$accountAD";
    be something like:
    $dbm{$accountID} = $accountAD;
    So you're not overwriting the same hash item each time?

    rdfield

      I didn't realise I was writing over data because of $dbm{'verified'}. Now when I think about it a million values of

      verified => 1
      verified => 2
      verified => 3

      wouldn't really work like I expected. And you're right, that was the problem. Thanks for your help!!

      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
Re: Database not storing data
by l2kashe (Deacon) on Feb 13, 2003 at 14:20 UTC
    2 comments

    1) You aren't testing whether the tie is successful or not, so you may not open the db at some point, but go on happily processing your data.

    2) I have found in situations, that sometimes (due to filesystem level buffering and such) that I need to untie and then retie a local db in order to view all the changes I have made this run.

    Just my 2 cents.

    /* And the Creator, against his better judgement, wrote man.c */
Re: Database not storing data
by sulfericacid (Deacon) on Feb 13, 2003 at 09:51 UTC
    Incase the problem wasn't clear, you can test out the script at this page. No, your info won't be stored so I can spam you, the database doesn't even work yet.

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid