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

I have a form where users sign up/remove themselves from a database. Problem is they can sign up but they cannot remove themselves. When they fill out the form to delete themselves it says everything should work (no errors are given) but when you check the database they're still up there. Can someone help me figure this out?

You can see the script at http://sulfericacid.perlmonk.org/neopets/add.pl.

use strict; use warnings; use POSIX; use CGI qw/:standard/; require SDBM_File; my %list; my $list = "list.dbm"; #change to location of database tie %list, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644; if ( !tied %list ) { print "database unsuccessful $!.\n"; } print header, start_html('Neopets I/S nickname list:'); print start_form(), table( Tr( td("Your username: "), td( textfield( -name => 'username', -size => 40 ) ) ), Tr( td("What you wish to be called: "), td( textfield( -name => 'askname', -size => 40 ) ) ), Tr( td( radio_group( -name => 'update', -values => [ 'add', 'rem' ] ) ), ), Tr( td(), td(submit) ), ), end_form(), hr(); print qq(<a href="list.pl">view the current list!</a><br><br><br>); if(param()){ my $username = param('username'); my $askname = param('askname'); my $update = param('update'); if($username){ if($username){ if($update eq "add"){ if(exists $list{$username}){ print "Username already exists in database.\n"; } else{ $list{$username} = $askname; print "Username was added to our system!<p>\n"; } } elsif($update eq "rem"){ if(exists $list{$username}){ del $list{$username}; print "Account information was removed from the sy +stem.\n"; } else{ print "Oops, it doesn't appear that username is in + our database.\n"; } } } else{ print "For this to work please add your username.\n"; } }else{ print "Unless your name is null, please go back and fill it in +.\n"; } } print end_html();


"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: deleting item from database
by Zaxo (Archbishop) on Jun 21, 2003 at 17:31 UTC

    I think that line 70, del $list{$username}; should be:     delete $list{$username}; I don't know why you don't get an error from del.

    After Compline,
    Zaxo

      That was definately the problem, Zaxo. I stepped away from perl for over a month and when I came back I was almost positive Perl made delete so the lazy people could use del instead. I use Primal Script for my editing and it didn't show any errors during a debug there are during a run through the web browser.

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

        I always put
        use CGI::Carp qw(fatalsToBrowser);
        in my CGIs, at least while I'm working on them. Makes debugging a whole lot easier.
Re: deleting item from database
by YuckFoo (Abbot) on Jun 21, 2003 at 18:07 UTC
    sulfericacid,

    I think you want to 'delete $list{username};', not 'del $list{username}; '

    YuckFoo