Your life may be easier if you do the following before going too much further:

1) use strict; at the top of your script.

2) use taint; on all CGI scripts-- not later after you get the logic built, but now when it's easy.

3) use CGI.pm; on all CGI scripts involving anything remotely resembling a form. There are approximately ten perl hackers worldwide who could write and understand a decent form handler in an efficient amount of time, and all of them would use CGI.pm unless they were in the process of rewriting CGI.pm.

4) There doesn't appear to be anything wrong with your if-else structure (although I'd probably use a loop of some sort if it were my script) except typos, but I sense that the code you've listed is not the actual code-- which makes it hard to spot the actual error or trouble you're having.

5) Note that once you use CGI.pm to both create and handle the submission form, you will get a stateful treatment of all the form elements so that if you test and find that one or more params are empty, you simply resend the form (perhaps with a note at the top that says, "error! you've missed the X and Y and Z fields.") and CGI.pm will fill in any values that have already been submitted.

For more information on using CGI effectively I strongly recommend the Tutorials on Outside Links. The perldocs for CGI are also pretty good (enough to get started on simple forms, for sure) and those are already available on any computer with Perl installed (as is the module).

In reply to (ichimunki)Re: Can someone help me adjust the below if then elsif statement: by ichimunki
in thread Can anyone adjust my script correctly:) by villa

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.