I am having trouble with my code. The conversion for both Fahrenheit and Celsius will not display, and when I select "Celsius to Fahrenheit", it gives me the conversion for Fahrenheit to Celsius. I'm not sure what I'm doing wrong. I've already searched for help and have gotten nowhere. So any help would be appreciated!
cgi script:
#!/usr/bin/perl
#c07case1.cgi - Temperature conversion
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use strict;
#variables
my ($temp, $fahConvert, $celConvert);
$temp = param('temp');
$fahConvert = param('fah');
$celConvert = param('cel');
#calculate
if (param('cel')) {
cel();
$celConvert = ($temp - 32) * 5 / 9;
}
else {
fah();
$fahConvert = $temp * 9 / 5 + 32;
}
sub cel {
print "<html>\n";
print "<head><title>Conversion from Celsius</title></head>\n";
print "<body>\n";
print "<h3>Celsius: $temp </h3>\n";
print "<h3>Fahrenheit: $fahConvert </h3>\n";
print "</body>\n";
print "</html>\n";
}
sub fah {
print "<html>\n";
print "<head><title>Conversion from Fahrenheit</title></head>\n";
print "<body>\n";
print "<h3>Fahrenheit: $temp </h3>\n";
print "<h3>Celsius: $celConvert </h3>\n";
print "</body>\n";
print "</html>\n";
}
HTML script:
<!c07case1.html>
<HTML>
<HEAD><TITLE>Washington Middle School</TITLE></HEAD>
<BODY>
<H1>Temperature Converter</H1>
<HR>
<FORM ACTION="https://crux.baker.edu/~wmorni01/cgi-bin/chap07_wendy_morningstar/c07case1.cgi" METHOD=POST>
<P><B>Temperature:</B> <INPUT TYPE=text NAME=temp></P>
<INPUT TYPE=radio NAME=Type Value=fah CHECKED>Fahrenheit to Celsius<BR>
<INPUT TYPE=radio NAME=Type Value=cel>Celsius to Fahrenheit<BR>
<P><INPUT TYPE=submit VALUE=Convert></P>
</FORM></BODY></HTML>
I'm really hoping it's something very simple...