[ back to toc ]

CGI Script

Date: 2002/03/14 09:53

I am taking a cgi class in college right now and I have learned absolutely
nothing. Our final is to get checkboxes on our teachers website to
temporarily save information so that we can link to the next persons part.
I do have the script somewhat done but it keeps telling me that I have
script errors. We are using a Unix server but I'm unsure of the version.
I'm going to copy the script on here so that hopefully you can help me.
The error is on line 16 which is under the assign input variables. The
line about the twosets. Well Heres my script I hope you can help me. Thank
you very much.
#final.cgi print "Content-type: text/html\n\n";
use CGI qw(:standard);

sub ReadParse {

#declare variables
my ($twosets, $shortterm, $longterm, @records);

my @twosets_count = ("Short-term Memory Problems","Long-term Memory
my %shortterm_count = ("Inconsistent auditory memory", "AUDMEM",
"Inconsistent visual memory", "VISMEM", "Poor memory of physical
sequential tasks", "BOTHMEM","It takes 10-15 repetitions over several days
for an LD child to retain what the average child retains in 3-5
repetitions on one occasion", "REPETITIONS", "Disrupted flow of ideas in
speech.", "DISRSPEECH","Disrupted flow of ideas in writing", "DISRWRIT");
my %longterm_count = ("Long-term memory deficits are a sign of mental

#assign input items to variables:
$twosets = param('TWOSETS');
$shortterm = param('SHORTTERM');
$longterm = param('LONGTERM');

#save form data to a file
open(OUTFILE, ">>file.txt")
or die "Error opening survey.txt.";
print OUTFILE "$twosets,$shortterm,$longterm\n";

#calculate survey statistics
open(INFILE, "<file.txt")
or die "Error opening survey.txt.";
@records = <INFILE>;
foreach my $rec (@records) {

($twosets, $shortterm, $longterm) = split(/,/, $rec);
$twosets_count[$twosets] = $twosets_count[$twosets] + 1;
$shortterm_count{$shortterm} = $shortterm_count{$shortterm} + 1;
$longterm_count{$longterm} = $longterm_count{$longterm} + 1;

$SENDMAIL="/usr/lib/sendmail -t";


local (*in) = @_ if @_; local ($i, $loc, $key, $val);
if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
$in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2);
$FOUND=0; foreach (@FIELDS) { $FOUND=1 if ($key eq $_); }
if (($key ne 'TO')&&($key ne 'SUBJECT')&&($key ne
{ push(@FIELDS,$key); }
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val; } return 1; }

foreach (@FIELDS) {&MissingInfo if (($in{$_} eq

$SUBJECT=$in{'SUBJECT'}; delete $in{'SUBJECT'};
$REPLYTO=$in{'REPLY-TO'}; delete $in{'REPLY-TO'};

# split up the "to" names for multiple recipients
$TO=$in{'TO'}; @TO=split('\0',$TO);

# Open Sendmail and do our thing
open (SENDMAIL,"| $SENDMAIL") || die "Ain't Gonna Happen";
print SENDMAIL "To: @TO[0]\n";
if ($#TO > 0) { foreach (1..$#TO) { print SENDMAIL "Cc: @TO[$_]\n"; }
delete $in{'TO'}; }
print SENDMAIL "Subject: $SUBJECT\n";
print SENDMAIL "Reply-To: $REPLYTO\n";

# Display each field and responses
foreach (@FIELDS) {
$in{$_}=~ s/\0/\n\n * /g;
print SENDMAIL "---------------------------------------------------\n";
print SENDMAIL "Input Field: $_\n";
print SENDMAIL "Response:\n * $in{$_}\n";
print SENDMAIL "---------------------------------------------------\n";

# Read in the response and print it.
undef $/; $_=<DATA>; print;

# What to display as the "missing information" error
sub MissingInfo {
print <<EOF;
<H1 ALIGN=CENTER>Error: Fields left empty</H1>
You are required to fill in all the fields in this response form.
Please go back and fill in the fields with missing information.

# Everything down here is the default response.
<H1 ALIGN=CENTER>Thank You!</H1>
Thanks for responding to this form. Your responses have been mailed to
the correct person.<P>

There is a ; missing on that line.


[ back to toc ]