Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:37:22+00:00 2026-05-27T04:37:22+00:00

This is my first attempt at CGI (I know some Perl) but i’m falling

  • 0

This is my first attempt at CGI (I know some Perl) but i’m falling on my face.

I want to enter a form and check it – but the check section isn’t seeing the submitted values at all.

I am running this directly as http://example/cgi-bin/formcheck.cgi – there is no HTML calling this.

I suspect it’s running, dropping out the bottom and then running from scratch whenever a button is pressed. I’m not sure though. Here’s my code:

#!/usr/bin/perl -w
use strict; # let's tighten things up

use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);

print header;
print start_html("form check");
print "<h1>form check</h1>\n";

print_questions();

print_checks();
print "<hr>\n";

print end_html;

sub print_questions {

  if ( !defined(param('action')) || param('action') eq 'New' ) {

    my $p = int(rand(10));          # fix error under strict
    my $q = int(rand(10));          # fix error under strict
    my $i = 0;                      # fix error under strict

    my @question = '';              # fix error under strict
    my @answer   = '';              # fix error under strict

    $question[$i] = "$p X $q =";
    $answer[$i]   =  $p * $q;

    print start_form;
    print "$question[$i]";
    print textfield(-name=>'response',-default=>'',-size=>3);
    print "<p>";
    print submit('action','New');
    print submit('action','Check');
    print end_form;
    print "<p>";

    param(-name=>'question',-value=>@question);
    param(-name=>'answer',-value=>@answer);
    print "<hr>\n";
  }

}

sub print_checks {

  if ( param('action') eq 'Check' ) {

    my $errors = 0;                    # fix error under strict
    my $i = 0;                         # fix error under strict

    my @question = param('question');  # fix error under strict
    my @answer   = param('answer');    # fix error under strict
    my @response = param('response');  # fix error under strict

    if ( $answer[$i] != $response[$i] ) {

      $errors++;
      print "<font color=#FF0000>";
    } else {
      print "<font color=#00FF00>";

    }

    print "$question[$i] = $answer[$i]";
    print "</font>";

    print "<p>";
    print start_form;
    print submit('action','New');
    print end_form;
    print "<p>";
    print "<hr>\n";

    if ($errors == 0) {

      print "CORRECT!<br>";
    } else {
      print "NOPE!<br>";

    }
  }
}

Any help greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:37:23+00:00Added an answer on May 27, 2026 at 4:37 am

    Ok, read your code again:

    You set an question and answer parameter, but they do not have
    any representation in the form. You need a hidden()-field to
    preserve them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

problem euler #5 i found the solution but i don't know why this first
This is my first attempt at a plugin but I think I'm missing the
This is my very first attempt at generating images on the fly. I want
This is my first attempt to inline Java code in Perl. We cannot use
This is my first attempt to prototype. I want to initiate an AJAX request
This is my first attempt at reverse engineering, and really, I don't know how
this if my first attempt at using streaming for WCF, and I am struggling
Because this is my first attempt at an extension method that seems quite useful
This is pretty strange (admitedly, this is my first attempt with python / sqlite),
I'm writing an application using DDD techniques. This is my first attempt at a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.