[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

perl script won't validate

Posted on 2004-08-26
4
Medium Priority
?
277 Views
Last Modified: 2012-06-27
I am trying to get my form to validate. The script should test the input and if there is an error display the @errors, but if the input is correct display a page that shows the results. Everything works except the validation part. When I test it, I don't get any syntax errors. Is there aproblem with my If statement?

The webpage: http://crux.baker.edu/tscott04/public_html/chap06/c06case1.html

The Script:

#assign values to variables
$name = param('Name');
$proj1 = param('Proj1');
$proj2 = param('Proj2');
$midterm = param('Midterm');
$final = param('Final');
$total_score = ($proj1 + $proj2 + $midterm + $final);

#validate input data
if ($proj1 > 50 and $proj1 == "") {
      push(@errors, "Please enter a score between 0-50 for Project 1.");
}
 
if ($proj2 > 50 and $proj2 == "") {
      push(@errors, "Please enter a score between 0-50 for Project 2.");
}


if ($midterm > 100 and $midterm == "") {
      push(@errors, "Please enter a score between 0-100 for Midterm.");
}


if ($final > 100 and $final == "") {
      push(@errors, "Please enter a score between 0-100 for Final.");
}

#determine size of @errors array
$size = @errors;

#process input data or display error page
if ($size == 0) {
      #process input data
#print name and final score to file
open(OUTFILE, ">> c06case1.txt")
      or die "Error opening c06case1.txt. $!, stopped";
print OUTFILE "$name, $total_score\n";
close(OUTFILE);

#generate HTML acknowledgement
print "<HTML>\n";
print "<HEAD><TITLE>Mountain Community College</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H3>A record for $name with a total of $total_score has been saved.</H3>\n";
print "</BODY>\n";
print "</HTML>\n";

}
else {
#display error page
      print "<HTML><HEAD><TITLE>Mountain Community College</TITLE></HEAD>\n";
      print "<BODY>\n";
      print "<H3>Please use your browser's back button to \n";
      print "return to the form to make the following corrections: </H3><BR>\n";
      for(my $x=0; $x<$size; $x+1) {
            print "$errors[$x]<BR>\n";
      }
      print "</BODY></HTML>\n";      


}

0
Comment
Question by:reesecup999
  • 3
4 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 11908840
$proj1 == ""
is a strange way to write
$proj1 == 0

$proj1 > 50 and $proj1 == ""
will never be true
0
 
LVL 85

Expert Comment

by:ozo
ID: 11908901
Perhaps you meant "or" instead of "and"
0
 
LVL 85

Expert Comment

by:ozo
ID: 11908943
Perhaps you also meant "eq" instead of "=="
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11909329
Given that it's an assignment, we can't feed you too much (ozo has already given you plenty).

If you convert the if logic into English you get:

If proj1 is greater than 50 and is blank then set an error message.

Unless you live in a very Zen world, I'm sure you can see the flaw in the logic.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question