I'm running Apache2 on a NW 6.5 server. Here's my problem. I execute a script called makequiz.cgi which reads a text file and displays the questions in the browser. Currently there are 5 questions in this file.
After answering the questions and pressing the "Grade Quiz" button, the data is sent to a script called gradequiz.cgi which displays the questions and the correct answer and whether you got the question right/wrong.

The first time I run makequiz.cgi and answer the questions and submit them, the scripts run just fine. If I then go back and click the link again to execute makequiz.cgi, the questions are displayed ok, but when I submit the questions to gradequiz.cgi,

1. not all of the variables are passed to gradequiz. It grades the quiz indicating which questions are wrong/right but it does not pass the correct and incorrect answers or the user's name 2. It lists all the questions twice, questions 1-5 which it grades accurately, then redisplays the questions as 6-10, all of which are marked as wrong.
If I repeat the above by clicking the link to start the makequiz.cgi script, it does the same thing listed above only it now displays the questions 3 times, meaning it shows 15 questions. I'm sure it is something simple but I'm lost.

Here is my code for the makequiz:

print "<H2>Hello $fullname!</H2><P>"; print start_form (-name=>'makequiz', -method=>'POST', -action=>"http:/ +/ist221.nsm.tridenttech.edu/perl/gradequiz.cgi"); chdir("/perl/web"); open FILE, "$file" || die "Cannot open $file: $!"; while (<FILE>) { # ** READS EACH LINE OF TEXT FROM FILE chomp; # ** BY DEFAULT, CHOMPS OFF $/ F +ROM EACH LINE ($type, $value) = split (/:#\s*/, $_); # ***** SPLITS EACH LIN +E BY TYPE AND CONTENT if ($type =~ m/i/i) { # ** CHECKS FOR IMAGE print "<IMG SRC=http://ist221.tridenttech.edu/images/$courselocation/$ +value>"; print "<P>"; }elsif ($type =~ m/q/i) { # ** CHECKS FOR QUESTION LINE & PRINT +S QUESTION $questionno++; print "<B>$questionno. $value</B><BR>"; push(@allquestions, $value); }elsif ($type =~ m/a/i) { # ** CHECKS FOR ANSWER LINE @answers = split (/`\s*/, $value); $anslength = @answers; # ** LENGTH OF @ANSWERS push(@allanswers, $value); }elsif ($type =~ m/s/i) { # ** CHECKS FOR SELEC +TION LINE $buttonname = $type . $questionno; push(@allselections, $value); %selections = split (/`\s*/, $value); @options = keys (%selections); if ($anslength > 1) { # ** DETERMINE +S TO USE RADIO OR CHECKBOX print "<BR>"; print checkbox_group(-name=>$buttonname, -v +alues=>\@options, -linebreak=>'true', -labels=>\%selections); }else { print "<BR>"; print radio_group(-name=>$buttonname, -values +=>\@options, -linebreak=>'true', -labels=>\%selections, -default=>'-' +); } print "<BR><HR><BR>"; }elsif ($type =~ m/e/i) {# ** CHECKS FOR EXPLAINATION +LINE push (@explain, $questionno, $value); } # END ELSIF STATEMENTS } # ** END WHILE STATEMENT close (FILE); print "<CENTER>"; # ** THIS SECTION SENDS THREE ARRAYS TO THE GRADEQUIZ.CGI print hidden(-name=>"answers", -default=>\@allanswers); print hidden(-name=>"questions", -default=>\@allquestions); print hidden(-name=>"selections", -default=>\@allselections); print hidden(-name=>"explain", -default=>\@explain); print hidden(-name=>'fname', -value=>$fname); print hidden(-name=>'lname', -value=>$lname); print hidden(-name=>'reviewtime', -value=>$reviewtime); print hidden(-name=>'file', -value=>$file); print hidden(-name=>'id', -value=>$idinput); print submit (-value=>'Grade'); print "</CENTER>"; print end_form; } print "The last element in the questions array is $#allquestions<p>"; # ************************* END SUBROUTINE MAKEEXAM print end_html;

Thanks,
Chris

janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention

Retitled by davido from 'Unusual problem'.


In reply to Unusual problem with CGI based quiz by chriso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.