The part we are concerned about is the $sig database and the final if loop on the bottom of the page. After filling out the form and clicking 'save' you get the message saying it's saved and it prints it to screen as assurance. However it doesn't stay in the database, it just disappears and I'm not assigning anything else to it.
I really need to know what I'm doing wrong, this is such a mental strain for me.
#!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw/:standard/; require SDBM_File; my %sig; my $sigsave = "sig.dbm"; my %emails; my $list = "list.dbm"; my $adminmail = "admin\@test.com"; my $sendmail = "/usr/lib/sendmail"; my $signature; tie %emails, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644; if ( !tied %emails ) { print "database unsuccessful $!.\n"; } tie %sig, 'SDBM_File', $sigsave, O_CREAT | O_RDWR, 0644; if ( !tied %sig ) { print "database unsuccessful $!.\n"; } print header, start_html('Email Management'); print "DB contents: $sig{$signature}\n"; print start_form(), table( Tr( td("Subject: "), td( textfield( -name => 'subject', -size => 40 ) ) ), Tr( td("Message: "), td( textarea( -name => 'message', -columns => 40, -rows => 5 ) ) ), Tr( td("Signature: "), td( textarea( -name => 'signature', -default => $sig{$signature}, -columns => 40, -rows => 5 ) ) ), Tr( td( checkbox_group( -name => 'todo', -values => [ 'use', 'save' ], -rows => 2, -columns => 2 ), ), td(submit) ), ), end_form(), hr(); # rid ourselves from those nasty params my $message = param('message'); my $subject = param('subject'); my $signature = param('signature'); my $todo = param('todo'); if ( param() ) { if ( $message && $subject eq "" ) { print "Your subject or email content was missing.\n"; } else { foreach my $key ( keys %emails ) { print "Things we have: $key <br>\n"; } print "<br>\n"; while ( my ( $key, $value ) = each(%emails) ) { # Email Subs, special commands $message =~ s/\[name\]/$value/; #[name] = user name open( MAIL, "| $sendmail -t" ); print MAIL "To: $key\n"; print MAIL "From: $adminmail\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$message\n"; if ( $todo eq "use" && $signature ne "" ) { print MAIL "$signature\n"; } print MAIL ".\n"; close(MAIL); print "Email was sent to: $key !<br>"; } } if ( $todo eq "save" ) { print "<br>"; print "Saving to database<br>\n"; $sig{$signature} = $signature; print "\$sig{\$signature}: $sig{$signature}"; } } untie %emails; untie %sig;
In reply to $var{$var1} = $var1; ? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |