Auto-write script- help needed

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

I re-wrote a script I bought, and I get a 500 error. Permissions are set and it was uploaded in ascii form. Here is the script.
Please tell me if you find any errors.

#!/usr/local/bin/perl
#######Variables########
$view = '<a href="view.cgi">Click Here</a>';
$click = '<a href="http://www.myginleague.com/test2/new.html">Click Here</a> to create a new account';
$thank_you = "Thank you for submitting the results of your game. Your account has been updated. $view to see the updated stats list.";
$body = "bgcolor=green";

###############################################
############ STOP EDITING VALUES ##############
###############################################


$m = 0;
$n = 0;
$name = $formdata{'name'};
$opp = $formdata{'opp'};
$target = $formdata{'target'};
$pass1 = $formdata{'pass1'};
$pass2 = $formdata{'pass2'};
$pass = $formdata{'pass'};
$email = $formdata{'e-mail'};
$pts = $formdata{'pts'};
$oppts = $formdata{'oppts'};
$one = 1;

open (DATABASE, "< /data1/hypermart.net/e-ngl/GIN/database.txt");
flock (DATABASE, 2);
@contents = <DATABASE>;
flock (DATABASE, 8);
close (DATABASE);

@info = values(%formdata);
open (DATABASE, "<< /data1/hypermart.net/e-ngl/GIN/database.txt");
foreach $info (@info) {
&mime;
print DATABASE "$info|";
print DATABASE "\n";
}
close(DATABASE);

$number = @contents;
foreach $item(@contents) {
@info = split(/\|/, $item);
if ($name eq $info[1]) {
  $info[0] = $info[0] - $one;
  @winloss = split(/-/, $info[2]);
          $winloss[1]++;
  $info[2] = join('-', $winloss[0],$winloss[1]);
  $info[3] = "$info[3] + $pts";
  $info[4] = "$info[4] + $oppts";
  $contents[$m] = "$info[0]\|$info[1]\|$info[2]\|$info[3]\|$info[4]\|$info[5]\|$info[6]";
  }
  $m++;
}


foreach $item(@contents) {
@info = split(/\|/, $item);
if ($opp eq $info[1]) {
  $info[0] = $info[0] + 2;
  @winloss = split(/-/, $info[2]);
  $winloss[0]++;
  $info[2] = join('-', $winloss[0],$winloss[1]);
  $info[3] = "$info[3] + $oppts";
  $info[4] = "$info[4] + $pts";
  $contents[$n] = "$info[0]\|$info[1]\|$info[2]\|$info[3]\|$info[4]\|$info[5]\|$info[6]";
}
$n++;
}

open (DATABASE, ">/data1/hypermart.net/e-ngl/GIN/database.txt");
flock (DATABASE, 2);
foreach $item(@contents) {
chomp($item);
print DATABASE "$item\n";
}
flock (DATABASE, 8);
close (DATABASE);


sub new {
if ($pass1 eq "" || $pass2 eq "") {
&Whoops('You must fill in both password fields so we know you did not make a spelling error');
}
if ($pass1 ne $pass2) {
&Whoops('The passwords do not match. Please go back and correctly submit your password');
}

foreach $line(@contents) {
@cont = split(/\|/, $line);
if ($name =~ m/$cont[1]/) {
&Whoops('That username has already been used. Please choose another');
}
}
open (DATABASE, ">> /data1/hypermart.net/e-ngl/GIN/database.txt");
flock (DATABASE, 2);
print DATABASE "0|$name|0-0|0|0|$pass1|$email \n";
flock (DATABASE, 8);
close (DATABASE);
&finished;
}
sub mime {
print "Content-type:text/html\n\n";
}

sub header {
print "<html><head><title>";
print "$_[0]";
print "</title></head><body bgcolor\=green>";
}
sub finished {
print "&mime";
print "<center><font color\=blue size\=4>";
print "Thank you</center></font>\n";
print "<font color\=yellow size\=2>You did the right thing. The changes you made should be up immediately.";
}
sub Whoops {
&mime;
&header;
print "<center>";
print "<font color=\"White\"><font size=+1>ERROR:</font><b> $_[0]</b><p>";
print "$click";
print "</center></font>";
&footer;
exit;
}
'

Laughing out loud

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

just a quick glance, but where is &footer?
(third to last line)

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

OK I rewrote it again. Here is the updated version
it executes, but writes nothing
[code]
#!/usr/local/bin/perl
use CGI;
$query = CGI->new;
#######Variables########
$view = 'Click Here';
$click = 'Click Here to create a new account';
$thank_you = "Thank you for submitting the results of your game. Your account has been updated. $view to see the updated stats list.";
$body = "bgcolor=green";

###############################################
############ STOP EDITING VALUES ##############
###############################################

print "Content-type:text/html\n\n";
$m = 0;
$n = 0;
$name = $query->param('name');
$opp = $query->param('opp');
$target = $query->param('target');
$pass1 = $query->param('pass1');
$pass2 = $query->param('pass2');
$pass = $query->param('pass');
$email = $query->param('e-mail');
$pts = $query->param('pts');
$oppts = $query->param('oppts');
$one = 1;

open (DATABASE, "< /data1/hypermart.net/e-ngl/GIN/database.txt");
flock (DATABASE, 2);
@contents = ;
flock (DATABASE, 8);
close (DATABASE);

if ($target eq "new") {
&new;
}
if ($name eq "") {
&Whoops('You have to enter your username');
}
if ($pass1 eq "") {
&Whoops('You must enter your password');
}

foreach $item(@contents) {
@items = split(/\|/, $item);
if ($name eq $items[1]) {
$thepass = $items[4];
chomp($thepass);
if ($pass eq $thepass) {
$pw = "true";
}
$un = "true";
}
}
foreach $item(@contents) {
@items = split(/\|/, $item);
if ($opp eq $items[1]) {
$on = "true";
}
}

if ($un eq "true" && $on eq "true" && $pw eq "true") {
$number = @contents;
foreach $item(@contents) {
@info = split(/\|/, $item);
if ($name eq $info[1]) {
$info[0] = $info[0] - $one;
@winloss = split(/-/, $info[2]);
$winloss[1]++;
$info[2] = join('-', $winloss[0],$winloss[1]);
$info[3] = "$info[3] + $pts";
$info[4] = "$info[4] + $oppts";
$contents[$m] = "$info[0]\|$info[1]\|$info[2]\|$info[3]\|$info[4]\|$info[5]\|$info[6]";
}
$m++;
}

foreach $item(@contents) {
@info = split(/\|/, $item);
if ($opp eq $info[1]) {
$info[0] = $info[0] + 2;
@winloss = split(/-/, $info[2]);
$winloss[0]++;
$info[2] = join('-', $winloss[0],$winloss[1]);
$info[3] = "$info[3] + $oppts";
$info[4] = "$info[4] + $pts";
$contents[$n] = "$info[0]\|$info[1]\|$info[2]\|$info[3]\|$info[4]\|$info[5]\|$info[6]";
}
$n++;
}

open (DATABASE, ">/data1/hypermart.net/e-ngl/GIN/database.txt");
flock (DATABASE, 2);
foreach $item(@contents) {
chomp($item);
print DATABASE "$item\n";
}
flock (DATABASE, 8);
close (DATABASE);

sub new {
if ($pass1 eq "" || $pass2 eq "") {
&Whoops('You must fill in both password fields so we know you did not make a spelling error');
}
if ($pass1 ne $pass2) {
&Whoops('The passwords do not match. Please go back and correctly submit your password');
}
}
foreach $line(@contents) {
@cont = split(/\|/, $line);
if ($name =~ m/$cont[1]/) {
&Whoops('That username has already been used. Please choose another');
}
}
open (DATABASE, ">> /data1/hypermart.net/e-ngl/GIN/database.txt");
flock (DATABASE, 2);
print DATABASE "0|$name|0-0|0|0|$pass1|$email \n";
flock (DATABASE, 8);
close (DATABASE);
&finished;
}
sub mime {
print "Content-type:text/html\n\n";
}

sub header {
print "";
print "$_[0]";
print "";
}
sub finished {
print "Content type: text/html\n\n";
print "";
print "Thank you\n";
print "You did the right thing. The changes you made should be up immediately.";
}
sub Whoops {
&mime;
&header;
print "";
print "ERROR: $_[0]";
print "$click";
print "";
exit;
}

Laughing out loud

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.