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

When i click a submit on the form for a guest book the cgi script dies and leaves a message on the web server error log(Apache running on linux) that i can't open dbm file.So what possible wrong with the script.While i execute the same program on the command line it executes and creates a db file.So can any one help me find out what's wrong???

code is a follows

#!/usr/bin/perl $temp = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $temp); foreach $item(@pairs){ ($key, $content) = split(/=/, $item, 2); $content =~ tr/+/ /; $content=~ s/%(..)/pack("c",hex($1))/ge; $fields{$key}=$content; } print "Content-type: text/html\n\n"; #when header written here generates an error can't open #dbm file in t +he server error log. dbmopen(%users,"friends", 0666) || die "Can't open DBM file"; print "Content-type: text/html\n\n"; #when header written here generates an error premature #ending of head +ers in the server error log. if (!defined($users{$fields{'email'}})) { $users{$fields{'email'}}="$fields{'firstname'}::$fields{'lastname'}::$ +fields{'cont'}::$fields{'gender'}::$fields{'State'}::$fields'country' +}::$fields'gender'}::$fields{'age'}"; } else { print "Someone has already registered from that e-mail address. Sor +ry."; }

Edit by dws to add <code> tags

Replies are listed 'Best First'.
Re: problem with creation of db file
by diotalevi (Canon) on Oct 11, 2002 at 21:57 UTC

    And this is where the $! variable comes in handy. dbmopen is deprecated in general but that's not the main problem. Whatever the error is you just aren't logging it. Add that bit in try again.

    __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B:: +svref_2object(sub{})->OUTSIDE
Re: problem with creation of db file
by dorko (Prior) on Oct 12, 2002 at 02:14 UTC
    When i click a submit on the form for a guest book the cgi script dies and leaves a message on the web server error log(Apache running on linux) that i can't open dbm file. While i execute the same program on the command line it executes and creates a db file.
    I'd take a look at permissions. Apache often runs as "nobody". I'm guessing that "nobody" doesn't have permission to create and / or read the files in question while the user you use test the script does have the permissions to create and read the files.

    I hope this helps.

    Cheers!

    Brent

    -- Yeah, I'm a Delt.