New Script- Please HELP!!!
Ok I have tried everything to get this to work.
Please someone look at this
It will execute, but not write to the file.
#!/usr/local/bin/perl
use CGI;
$query = CGI->new;
#######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 ##############
###############################################
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 = <DATABASE>;
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 "<html><head><title>";
print "$_[0]";
print "</title></head><body bgcolor\=green>";
}
sub finished {
print "Content type: text/html\n\n";
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>";
exit;
}