Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Mysterious "1" in output

Posted on 1999-10-11
2
Medium Priority
?
210 Views
Last Modified: 2010-03-04

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;
}
0
Comment
Question by:thewebperson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
dougis earned 200 total points
ID: 2116656
From a quick glance I would say you are getting the return of the function printed as well (actually the exit status) Try changing the function call from
print tnklstinf();
to
tnklstinf();
and I think you will be all fixed.

0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 2116686
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

704 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