Welcome to WebmasterWorld Guest from 54.198.69.193

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Can't open database file

     
12:10 pm on Jun 16, 2011 (gmt 0)

5+ Year Member



I'm trying to use a text type DBM file but can't extract the values from the keys. I'm getting a message in the browser that says "Can't open english.db:Permission denied". I did alot of searching on this one to no avail.

Script looks like this:

#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use DB_File;
use Fcntl;
print"Content-Type:text/html\n\n";

my(%hexcodes,$dbm,%HASH,%hash,$red);
my $dbm="colors.db";
tie (%HASH, "DB_File", $dbm)or die "Can't open $dbm:$!\n";

my $red=$hexcodes{'red'};
print"$red";

untie %hash;

colors.db looks like this(separate file)I tried using the .txt extension but getting the same results.

%hexcodes('red' => 'ff0000',
'black' => '000000',
'white' => 'ffffff'
)
5:04 pm on Jun 16, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Is that your full script? Where does english.db come in?

Is the .db in cgi-bin? Try storing it in a different directory and using the full path.

/cgi-bin/yourscript.cgi
/httpdocs/data/colors.db

my $dbm = $ENV{'DOCUMENT_ROOT'} . "/data/colors.db";
6:16 pm on Jun 16, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Is the database-file read- and writable by the user the cgi-script runs as?
If apache is not configured with suexec/mod_suid2/mod_ruid, that's usually not the same user you upload stuff as.
Try chmod'ing the db-file to 777 (read & write for all) and see if that works.
12:51 am on Jun 18, 2011 (gmt 0)

5+ Year Member



I was living up to my name typo when I made this post. The file english.db was the mistake. Any way got that fixed. Problem now is when I open the script as posted below I get a "0"(zero) appearing on the browser screen.

#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use DB_File;
use Fcntl;
print"Content-Type:text/html\n\n";
my(%colors,$dbfile,%HASH,%hash);
my $dbfile="/home/users/web/b362/ipw.typomaniac101/public_html/cgi-bin/colors.txt ";
tie (%HASH, "DB_File", $dbfile)or die "Can't open $dbfile: $!\n";

my %colors;
print"$colors{'ffffff'}";
print"$colors{'000000'}";
print"$colors{'ff0000'}";
untie %hash

colors.txt is as follows

%colors=(
'ff0000' =>'red'
'000000' => 'black'
'ffffff' => 'white'
)

If I add any html anywhere on the page it appears and the zero goes away but am getting nothing from the text file. I tried putting the .txt file in the cgi-bin and also the httdocs area with the same results.
2:44 am on Jun 18, 2011 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



have you tried running your cgi script from the command line to see the actual output?

also, unless i'm missing something the %colors hash appears to be unevaluated in your script.
7:56 am on Jun 18, 2011 (gmt 0)

5+ Year Member



phranque....not sure how one goes about running from the command line. Also, how would I go about evaluating the %colors hash? I'm wanting to learn. I'm just getting over the shock of making everything in the strict mode.

Software error:

Can't locate /home/deploy/webmasterworld/code_format-v6.lib in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at decode-post-v6.lib line 27, <THREADDAT> line 8.

For help, please send mail to the webmaster (it@imninjas.com), giving this error message and the time and date of the error.