Link to home
Start Free TrialLog in
Avatar of thewebperson
thewebperson

asked on

Mysterious "1" in output


http://www.accesscom.com/~jcole/cgi-bin/lstreqtstb.cgi 

When the form is correctly filled out, the message
"Thank you for submitting your information1"
is displayed -- except I didn't put a 1 in my code.
How do I get rid of it?

Here's the code. The function that displays the message is
tnklstinf().

#!/usr/bin/perl -w
#script: lstreqtstb.cgi
use strict;
use CGI;
my $q = new CGI;
print $q->header();
print "<HTML><HEAD><TITLE></TITLE>";
print <<'Scripting';
<SCRIPT LANGUAGE="JavaScript">
function verinp(frm)
{
   var msg = "";
   var empty_fields = "";
   var val = "";
   
   for (var i = 0; i < frm.length; i++)
   {
      var emt = frm.elements[i];
alert(empty_fields);
alert(emt.name);
      if ((emt.name == "submit") || (emt.name == "send"))
         continue;
      if ((emt.name == "restaurant name") || (emt.name == "restaurant address") || (emt.name
== "restaurant city") || (emt.name == "first name") ||
         (emt.name == "last name") || (emt.name == "title") ||
         (emt.name == "email") || (emt.name == "password") ||
         (emt.name == "password again"))
      {
alert(emt.value);
         if ((emt.value == null) || (emt.value == "") || isBlank(emt.value))
         {
            empty_fields += "\n          " + emt.name;
         }
      }
      if (emt.name == "country")
      {
alert(emt.options[emt.selectedIndex].value);
         if (emt.options[emt.selectedIndex].value == "United States")
         {
            if (!frm.state.options[emt.selectedIndex].value)
            {
               empty_fields += "\n          " + "state";
            }
            if (!frm.metropolitan_area.options[emt.selectedIndex].value)
            {
               empty_fields += "\n          " + "metropolitan area";
            }
         }
         else if ((emt.options[emt.selectedIndex].value) &&
(emt.options[emt.selectedIndex].value != "United States"))
         {
            if (!frm.province_or_region.value
            || isBlank(frm.province_or_region.value))
               empty_fields += "\n          " + "province or region";
         }
         else
         {
             empty_fields += "\n          " + "country";
         }
      }
      if ((emt.name == "cuisine") || (emt.name == "price range"))
      {
alert(emt.options[emt.selectedIndex].value);
         if (!emt.value)
            empty_fields += "\n          " + emt.name;
      }
   }
   if (!empty_fields) return true;
   if (empty_fields)
   {
   msg += "You must fill in all required fields.\n\n"
   msg += "Fill in the following empty fields:"
      + empty_fields + "\n";
   }
   alert(msg);
   return false;
}
function isBlank(str)
{
   for (var i = 0; i < str.length; i++)
   {
      var chr = str.charAt(i);
      if ((chr != ' ') && (chr != '\n') && (chr != '\t')) return false;
   }
   return true;
}
</SCRIPT>
Scripting
;
print "</HEAD><BODY>";
if ($q->param())
{
   #write them to request file
   wrtreqfil();

   # thank for info
   print tnklstinf();
}
else
{
   # print the form
   prtlstinffrm();
}
print $q->end_html();
# write parameters to request file
sub wrtreqfil
{
   my $record_number = getrecnum();
   my ($day, $month, $year) = (localtime)[3 .. 5];
   ++$month;
   $year %= 100;
   my $todays_date = sprintf '%.2d/%.2d/%.2d', $month, $day, $year;
   open(REQFIL,">>lstreq.txt");
   print REQFIL "|$record_number|$todays_date|*";
   my $name;
   my $value;
   foreach $name ($q->param())
   {
      $value = $q->param($name);
      if ($value ne "Send")
      {
      $value =~ s/^\s+//;
      $value =~ s/\s+$//;
      print REQFIL "|$value";
      }
   }
  print REQFIL "\n";
   close(REQFIL);
}
sub tnklstinf
{
   print "Thank you for submitting your information";  
}
sub prtlstinffrm
{
   print <<EndForm
    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=10 WIDTH="400"
BGCOLOR="#FFFFFF">
    <tr><td><VALIGN=TOP>
    <FORM NAME = "listing"  ACTION="lstreq.cgi" METHOD="post" onSubmit="return
verinp(this);">
    Restaurant name<br>
    <INPUT type="text" name="restaurant name" size="40"><p>
    Street address<br>
    <INPUT type="text" name="restaurant address" size="40"><p>
    City<br>
    <INPUT type="text" name="restaurant city" size="40"><p>
    Country<br>
    <SELECT name="country">
    <OPTION></OPTION>
    <OPTION>Afghanistan</OPTION>
    <OPTION>Albania</OPTION>
    <OPTION>Algeria</OPTION>
    <OPTION>Andorra</OPTION>
    <OPTION>Angola</OPTION>
    <OPTION>Antigua</OPTION>
    <OPTION>Argentina</OPTION>
    <OPTION>Armenia</OPTION>
    <OPTION>Australia</OPTION>
    <OPTION>Austria</OPTION>
    <OPTION>Azerbaijan</OPTION>
    <OPTION>Bahamas</OPTION>
    <OPTION>Bahrain</OPTION>
    <OPTION>Bangladesh</OPTION>
    <OPTION>Barbados</OPTION>
    <OPTION>Belarus</OPTION>
    <OPTION>Belgium</OPTION>
    <OPTION>Belize</OPTION>
    <OPTION>Benin</OPTION>
    <OPTION>Bhutan</OPTION>
    <OPTION>Bolivia</OPTION>
    <OPTION>Bosnia</OPTION>
    <OPTION>Botswana</OPTION>
    <OPTION>Brazil</OPTION>
    <OPTION>Brunei</OPTION>
    <OPTION>Bulgaria</OPTION>
    <OPTION>Burkina</OPTION>
    <OPTION>Burundi</OPTION>
    <OPTION>Cambodia</OPTION>
    <OPTION>Cameroon</OPTION>
    <OPTION>Canada</OPTION>
    <OPTION>Cape Verde</OPTION>
    <OPTION>Central African Republic</OPTION>
    <OPTION>Chad</OPTION>
    <OPTION>Chile</OPTION>
    <OPTION>China</OPTION>
    <OPTION>Colombia</OPTION>
    <OPTION>Comoros</OPTION>
    <OPTION>Congo</OPTION>
    <OPTION>Costa Rica</OPTION>
    <OPTION>Croatia</OPTION>
    <OPTION>Cuba</OPTION>
    <OPTION>Cyprus</OPTION>
    <OPTION>Czech Republic</OPTION>
    <OPTION>Cote d'Ivoire</OPTION>
    <OPTION>Denmark</OPTION>
    <OPTION>Djibouti</OPTION>
    <OPTION>Dominica</OPTION>
    <OPTION>Dominican Republic</OPTION>
    <OPTION>Ecuador</OPTION>
    <OPTION>Egypt</OPTION>
    <OPTION>El Salvador</OPTION>
    <OPTION>Equatorial Guinea</OPTION>
    <OPTION>Eritrea</OPTION>
    <OPTION>Estonia</OPTION>
    <OPTION>Ethiopia</OPTION>
    <OPTION>Fiji</OPTION>
    <OPTION>Finland</OPTION>
    <OPTION>France</OPTION>
    <OPTION>Gabon</OPTION>
    <OPTION>Gambia</OPTION>
    <OPTION>Georgia</OPTION>
    <OPTION>Germany</OPTION>
    <OPTION>Ghana</OPTION>
    <OPTION>Greece</OPTION>
    <OPTION>Grenada</OPTION>
    <OPTION>Guatemala</OPTION>
    <OPTION>Guinea</OPTION>
    <OPTION>Guyana</OPTION>
    <OPTION>Haiti</OPTION>
    <OPTION>Honduras</OPTION>
    <OPTION>Hungary</OPTION>
    <OPTION>Iceland</OPTION>
    <OPTION>India</OPTION>
    <OPTION>Indonesia</OPTION>
    <OPTION>Iran</OPTION>
    <OPTION>Iraq</OPTION>
    <OPTION>Ireland</OPTION>
    <OPTION>Israel</OPTION>
    <OPTION>Italy</OPTION>
    <OPTION>Jamaica</OPTION>
    <OPTION>Japan</OPTION>
    <OPTION>Jordan</OPTION>
    <OPTION>Kazakhstan</OPTION>
    <OPTION>Kenya</OPTION>
    <OPTION>Kiribati</OPTION>
    <OPTION>Korea, North</OPTION>
    <OPTION>Korea, South</OPTION>
    <OPTION>Kuwait</OPTION>
    <OPTION>Kyrgyzstan</OPTION>
    <OPTION>Laos</OPTION>
    <OPTION>Latvia</OPTION>
    <OPTION>Lebanon</OPTION>
    <OPTION>Lesotho</OPTION>
    <OPTION>Liberia</OPTION>
    <OPTION>Libya</OPTION>
    <OPTION>Liechtenstein</OPTION>
    <OPTION>Lithuania</OPTION>
    <OPTION>Luxembourg</OPTION>
    <OPTION>Macedonia</OPTION>
    <OPTION>Madagascar</OPTION>
    <OPTION>Malawi</OPTION>
    <OPTION>Malaysia</OPTION>
    <OPTION>Maldives</OPTION>
    <OPTION>Mali</OPTION>
    <OPTION>Malta</OPTION>
    <OPTION>Marshall Islands</OPTION>
    <OPTION>Mauritania</OPTION>
    <OPTION>Mauritius</OPTION>
    <OPTION>Mexico</OPTION>
    <OPTION>Micronesia</OPTION>
    <OPTION>Moldova</OPTION>
    <OPTION>Monaco</OPTION>
    <OPTION>Mongolia</OPTION>
    <OPTION>Morocco</OPTION>
    <OPTION>Mozambique</OPTION>
    <OPTION>Myanmar</OPTION>
    <OPTION>Namibia</OPTION>
    <OPTION>Nauru</OPTION>
    <OPTION>Nepal</OPTION>
    <OPTION>Netherlands</OPTION>
    <OPTION>New Zealand</OPTION>
    <OPTION>Nicaragua</OPTION>
    <OPTION>Niger</OPTION>
    <OPTION>Nigeria</OPTION>
    <OPTION>Norway</OPTION>
    <OPTION>Oman</OPTION>
    <OPTION>Pakistan</OPTION>
    <OPTION>Palau</OPTION>
    <OPTION>Panama</OPTION>
    <OPTION>Paraguay</OPTION>
    <OPTION>Peru</OPTION>
    <OPTION>Philippines</OPTION>
    <OPTION>Poland</OPTION>
    <OPTION>Portugal</OPTION>
    <OPTION>Qatar</OPTION>
    <OPTION>Romania</OPTION>
    <OPTION>Russia</OPTION>
    <OPTION>Rwanda</OPTION>
    <OPTION>Saint Kitts</OPTION>
    <OPTION>Saint Lucia</OPTION>
    <OPTION>Saint Vincent</OPTION>
    <OPTION>San Marino</OPTION>
    <OPTION>Sao Tome</OPTION>
    <OPTION>Saudi Arabia</OPTION>
    <OPTION>Senegal</OPTION>
    <OPTION>Seychelles</OPTION>
    <OPTION>Sierra Leones</OPTION>
    <OPTION>Singapore</OPTION>
    <OPTION>Slovakia</OPTION>
    <OPTION>Slovenia</OPTION>
    <OPTION>Solomon Islands</OPTION>
    <OPTION>Somalia</OPTION>
    <OPTION>South Africa</OPTION>
    <OPTION>Spain</OPTION>
    <OPTION>Sri Lanka</OPTION>
    <OPTION>Sudan</OPTION>
    <OPTION>Suriname</OPTION>
    <OPTION>Swaziland</OPTION>
    <OPTION>Sweden</OPTION>
    <OPTION>Switzerland</OPTION>
    <OPTION>Syria</OPTION>
    <OPTION>Taiwan</OPTION>
    <OPTION>Tajikistan</OPTION>
    <OPTION>Tanzania</OPTION>
    <OPTION>Thailand</OPTION>
    <OPTION>Togo</OPTION>
    <OPTION>Tonga</OPTION>
    <OPTION>Trinidad</OPTION>
    <OPTION>Tobago</OPTION>
    <OPTION>Tunisia</OPTION>
    <OPTION>Turkey</OPTION>
    <OPTION>Turkmenistan</OPTION>
    <OPTION>Tuvalu</OPTION>
    <OPTION>Uganda</OPTION>
    <OPTION>Ukraine</OPTION>
    <OPTION>United Arab Emirates</OPTION>
    <OPTION>United Kingdom</OPTION>
    <OPTION VALUE = "United States">United States</OPTION>
    <OPTION>Uruguay</OPTION>
    <OPTION>Uzbekistan</OPTION>
    <OPTION>Vanuatu</OPTION>
    <OPTION>Vatican City</OPTION>
    <OPTION>Venezuela</OPTION>
    <OPTION>Vietnam</OPTION>
    <OPTION>Western Sahara</OPTION>
    <OPTION>Western Samoa</OPTION>
    <OPTION>Yemen</OPTION>
    <OPTION>Yugoslavia</OPTION>
    <OPTION>Zambia</OPTION>
    <OPTION>Zimbabwe</OPTION>
    </SELECT><p>
    <hr>
    <b>United States restaurants only:</b> choose state<br>
    <SELECT name="state">
    <OPTION></OPTION>
    <OPTION>Alabama</OPTION>
    <OPTION>Alaska</OPTION>
    <OPTION>Arizona</OPTION>
    <OPTION>Arkansas</OPTION>
    <OPTION>California</OPTION>
    <OPTION>Colorado</OPTION>
    <OPTION>Connecticut</OPTION>
    <OPTION>Delaware</OPTION>
    <OPTION>Florida</OPTION>
    <OPTION>Georgia</OPTION>
    <OPTION>Hawaii</OPTION>
    <OPTION>Idaho</OPTION>
    <OPTION>Illinois</OPTION>
    <OPTION>Indiana</OPTION>
    <OPTION>Iowa</OPTION>
    <OPTION>Kansas</OPTION>
    <OPTION>Kentucky</OPTION>
    <OPTION>Louisiana</OPTION>
    <OPTION>Maine</OPTION>
    <OPTION>Maryland</OPTION>
    <OPTION>Massachusetts</OPTION>
    <OPTION>Michigan</OPTION>
    <OPTION>Minnesota</OPTION>
    <OPTION>Mississippi</OPTION>
    <OPTION>Missouri</OPTION>
    <OPTION>Montana</OPTION>
    <OPTION>Nebraska</OPTION>
    <OPTION>Nevada</OPTION>
    <OPTION>New Hampshire</OPTION>
    <OPTION>New Jersey</OPTION>
    <OPTION>New Mexico</OPTION>
    <OPTION>New York</OPTION>
    <OPTION>North Carolina</OPTION>
    <OPTION>North Dakota</OPTION>
    <OPTION>Ohio</OPTION>
    <OPTION>Oklahoma</OPTION>
    <OPTION>Oregon</OPTION>
    <OPTION>Pennsylvania</OPTION>
    <OPTION>Puerto Rico</OPTION>
    <OPTION>Rhode Island</OPTION>
    <OPTION>South Carolina</OPTION>
    <OPTION>South Dakota</OPTION>
    <OPTION>Tennessee</OPTION>
    <OPTION>Texas</OPTION>
    <OPTION>Utah</OPTION>
    <OPTION>Vermont</OPTION>
    <OPTION>Virginia</OPTION>
    <OPTION>Wahington</OPTION>
    <OPTION>Washington D.C.</OPTION>
    <OPTION>West Virginia</OPTION>
    <OPTION>Wisconsin</OPTION>
    <OPTION>Wyoming</OPTION>
    </SELECT><p>
    Choose the closest metropolitan area<br>
    <SELECT name="metropolitan_area">
    <OPTION></OPTION>
    <OPTION>Albuquerque</OPTION>
    <OPTION>Anchorage</OPTION>
    <OPTION>Atlanta</OPTION>
    <OPTION>Baltimore</OPTION>
    <OPTION>Boston</OPTION>
    <OPTION>Charleston</OPTION>
    <OPTION>Chicago</OPTION>
    <OPTION>Denver</OPTION>
    <OPTION>Honolulu</OPTION>
    <OPTION>Las Vegas</OPTION>
    <OPTION>Los Angeles</OPTION>
    <OPTION>Memphis</OPTION>
    <OPTION>Miami</OPTION>
    <OPTION>New Orleans</OPTION>
    <OPTION>New York</OPTION>
    <OPTION>Orlando</OPTION>
    <OPTION>Philadelphia</OPTION>
    <OPTION>Phoenix</OPTION>
    <OPTION>Portland</OPTION>
    <OPTION>San Diego</OPTION>
    <OPTION>San Francisco</OPTION>
    <OPTION>Seattle</OPTION>
    <OPTION>Tuscon</OPTION>
    <OPTION>Washington D.C.</OPTION>
    <OPTION></OPTION>
    </SELECT><p>
    <hr>
    <b>Restaurants outside United States only:</b> type province or region<br>
    <INPUT type="text" name="province_or_region" size="40"><p>
    <hr>
    <b>All Restaurants:</b><br>
    Cuisine<br>
    <SELECT name="cuisine">
    <OPTION></OPTION>
    <OPTION>American</OPTION>
    <OPTION>Barbecue</OPTION>
    <OPTION>Brazilian</OPTION>
    <OPTION>Burgers</OPTION>
    <OPTION>Burmese</OPTION>
    <OPTION>Cajun</OPTION>
    <OPTION>Cambodian</OPTION>
    <OPTION>Caribbean</OPTION>
    <OPTION>Chilean</OPTION>
    <OPTION>Chinese</OPTION>
    <OPTION>Continental</OPTION>
    <OPTION>Delicatessen</OPTION>
    <OPTION>English</OPTION>
    <OPTION>Ethiopian</OPTION>
    <OPTION>French</OPTION>
    <OPTION>German</OPTION>
    <OPTION>Greek</OPTION>
    <OPTION>Hungarian</OPTION>
    <OPTION>Indian</OPTION>
    <OPTION>Indonesian</OPTION>
    <OPTION>Irish</OPTION>
    <OPTION>Italian</OPTION>
    <OPTION>Japanese</OPTION>
    <OPTION>Jewish</OPTION>
    <OPTION>Korean</OPTION>
    <OPTION>Lebanese</OPTION>
    <OPTION>Malaysian</OPTION>
    <OPTION>Mediterranean</OPTION>
    <OPTION>Mexican</OPTION>
    <OPTION>Middle Eastern</OPTION>
    <OPTION>Peruvian</OPTION>
    <OPTION>Pizza</OPTION>
    <OPTION>Polish</OPTION>
    <OPTION>Russian</OPTION>
    <OPTION>Scandanavian</OPTION>
    <OPTION>Seafood</OPTION>
    <OPTION>Singaporean</OPTION>
    <OPTION>Soul Food</OPTION>
    <OPTION>South American</OPTION>
    <OPTION>Spanish</OPTION>
    <OPTION>Steak</OPTION>
    <OPTION>Swiss</OPTION>
    <OPTION>Tex-Mex</OPTION>
    <OPTION>Thai</OPTION>
    <OPTION>Tibetan</OPTION>
    <OPTION>Turkish</OPTION>
    <OPTION>Various</OPTION>
    <OPTION>Other</OPTION>
    <OPTION>Vegetarian</OPTION>
    <OPTION>Vietnamese</OPTION>
    <OPTION>Other</OPTION>
    </SELECT><p>
    Average Price of an Entree<br>
    <SELECT name="price range">
    <OPTION></OPTION>
    <OPTION>under \$10</OPTION>
    <OPTION>\$10 - \$20</OPTION>
    <OPTION>\$20 - \$50</OPTION>
    <OPTION>over \$50</OPTION>
    </SELECT><p>
    Your first name<br>
    <INPUT type="text" name="first name" size="40"><p>
    Your last name<br>
    <INPUT type="text" name="last name" size="40"><p>
    Your title<br>
    <INPUT type="text" name="title" size="40"><p>
    Your email address<br>
    <INPUT type="text" name="email" size="40"><p>
    Choose a password (6 characters, letters and digits).<br>
    <INPUT type="password" name="password" size="6"><p>
    Type password again.<br>
    <INPUT type="password" name="password again" size="6"><p>
    <INPUT type="submit"  value="Send" name="submit">
    <INPUT type="reset" value="Reset" name="reset">

    </FORM>
    </td></tr>
    </TABLE>
   
EndForm
;
}

sub getrecnum
{
   open(RECNUMFIL,"recnum.txt");
   my $currecnum = <RECNUMFIL>;
   my $nxtrecnum = $currecnum + 1;
   open(RECNUMFIL,">recnum.txt");
   print RECNUMFIL $nxtrecnum;
   close(RECNUMFIL);
   chomp($currecnum);
   return $currecnum;
}
ASKER CERTIFIED SOLUTION
Avatar of dougis
dougis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prakashk021799
prakashk021799

dougis is right.

When you said "print tnklstinf()", first the subroutine tnklstinf() is being called and it prints the line you want and returns. The return value of the subroutine is, by default, is return value of the last statement executed (print "..."), which is 1. It is being printed in the caller routine.