We help IT Professionals succeed at work.

Reading form values using perl language

manu1076
manu1076 asked
on
Dear Sir,
I have been facing a problem regarding my perl script. This script runs fine at our machine, but when we upload it to our site, it give an error. Our domain have the cgi support. Please check with the script and plz suggest any changes to be done so that it functions properly on the web.
The script takes in  the input from the user and prints a thankz message on the user machine.
The form and the script follows next.


-----------------feedback.htm--------------------
<html>
<head>
<title>Suretex.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FEE9C0">
<p>&nbsp;</p>
<div id="Layer2" style="position:absolute; width:321px; height:39px; z-index:2; left: 208px; top: 13px">
  <h1 align="center"><font face="Bookman Old Style" color="#FF3333"><i><font color="#FF6600">GuestBook
    Form </font></i></font></h1>
</div>
<p>&nbsp;</p>
<div id="Layer1" style="position:absolute; width:500; height:115px; z-index:1; left: 26px; top: 54px">
  <form method="post" action="cgi-bin/feedback.cgi" name="feedback">
    <table width="121%" border="0" cellpadding="10">
      <tr>
        <td width="27%" height="57">
          <div align="right"><font face="Bookman Old Style" size="2"><b>Name</b></font></div>
        </td>
        <td width="73%" height="57">
          <div align="left"><font face="Bookman Old Style" size="2">
            <input type="text" name="name" size="30">
            </font></div>
        </td>
      </tr>
      <tr>
        <td width="27%">
          <div align="right"><font face="Bookman Old Style" size="2"><b>Company
            Name</b></font></div>
        </td>
        <td width="73%">
          <div align="left"><font face="Bookman Old Style" size="2">
            <input type="text" name="comname" size="50">
            </font></div>
        </td>
      </tr>
      <tr>
        <td width="27%">
          <div align="right"><font face="Bookman Old Style" size="2"><b>Address</b></font></div>
        </td>
        <td width="73%">
          <div align="left"><font face="Bookman Old Style" size="2">
            <input type="text" name="add1" size="50">
            </font></div>
        </td>
      </tr>
      <tr>
        <td width="27%" height="98">
          <div align="right"><font face="Bookman Old Style" size="2"><b>Phone
            No.</b></font></div>
        </td>
        <td width="73%" height="98">
          <div align="left">
            <p><font face="Bookman Old Style" size="2">
              <input type="text" name="phone1" size="30">
              (country code)-(area code)-(phone no.)</font></p>
            <p><font face="Bookman Old Style" size="2">
              <input type="text" name="phone2" size="30">
              </font></p>
          </div>
        </td>
      </tr>
      <tr>
        <td width="27%">
          <div align="right"><font face="Bookman Old Style" size="2"><b>Fax No.</b></font></div>
        </td>
        <td width="73%">
          <div align="left"><font face="Bookman Old Style" size="2">
            <input type="text" name="fax" size="30">
            </font></div>
        </td>
      </tr>
      <tr>
        <td width="27%">
          <div align="right"><font face="Bookman Old Style" size="2"><b>e-Mail</b></font></div>
        </td>
        <td width="73%">
          <div align="left"><font face="Bookman Old Style" size="2">
            <input type="text" name="email" size="30">
            </font></div>
        </td>
      </tr>
      <tr>
        <td width="27%">
          <div align="right"><font face="Bookman Old Style" size="2"><b>Comments</b></font></div>
        </td>
        <td width="73%">
          <div align="left"><font face="Bookman Old Style" size="2">
            <textarea name="comments" cols="60" rows="5"></textarea>
            </font></div>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <div align="center"><font face="Bookman Old Style" size="2">
            <input type="submit" name="Submit" value="Submit">
            <input type="reset" name="Submit2" value="Reset">
            </font></div>
        </td>
      </tr>
    </table>
  </form>
</div>
<p>&nbsp;</p>
</body>
</html>



-------------------------feedback.cgi---------------------------
#!/usr/bin/perl

$info_size = $ENV{'CONTENT_LENGTH'};
read (STDIN, $posted_info, $info_size);

$posted_info =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
$posted_info =~ s/\+/ /g;

@fields = split (/&/, $posted_info);
($label, $name) = split (/=/, $fields[0]);
($label, $comname) = split (/=/, $fields[1]);
($label, $add1) = split (/=/, $fields[2]);
($label, $phone1) = split (/=/, $fields[3]);
($label, $phone2) = split (/=/, $fields[4]);
($label, $fax) = split (/=/, $fields[5]);
($label, $email) = split (/=/, $fields[6]);
($label, $comments) = split (/=/, $fields[7]);


print "Content-type: text/html \n";
print "<html>";
print "<body bgcolor='#fcde9c'>";
            open (INFILE, ">> data.txt");

print INFILE $name," ? ",$comname, " ? ",$add1, " ? ",$phone1, " ? ",$phone2, " ? ",$fax, " ? ",$email, " ? ",$comments, "\n";
                        close(INFILE);                        


      
            print  "Thanks";


                        print  "<center><h1>Thanks for registering<br></h1></center>\n";
                                          
                        print  "To:  $name <BR>\n";
                        print  "From: Customer Support <support\@suretex.net><BR>\n";
                        print  "Subject: Welcome to suretex.net<BR><BR>\n\n";
                        print  "Dear $name,<BR>";
                        print  "Thank you for visiting suretex.net. It's a great pleasure to have you on board.<BR><BR>\n\n";
                        print  "You can feel the pleasure of having business with the SURETEX INC., Gurgaon .<BR>\n";
                        print  "If you have any further questions please feel free to contact our support team at: <a href=\"mailto:info\@suretex.net\">support\@suretex.net</a><BR>\n";
                        print  "Thanks again for visiting suretex.net. We look forward to satisfy all your needs!<BR><BR>\n\n";
                        print  "Sincerely,<BR>\n";
                        print  "suretex.net Customer Support.<BR><br><br>";
                        
                  

            
print "<br><br><br><br><br><font align=right><a href=../contact.htm><<< Back</a></font>\n";
print "</body>\n";
print "</html>\n";

Comment
Watch Question

CERTIFIED EXPERT
Commented:

What error message are you receiving?

Here are two things that immediately come to sight:

1. On the following line:

print "Content-type: text/html \n";

There should be two \n's like:

print "Content-type: texst/html \n\n";

2. The following line indicates that you are appending data to a file:

open (INFILE, ">> data.txt");

Does your *web server* have permission to write to the file?  Oftentimes, the web server is not run under your own personal user id - you may need to change ownership of the file to that of the web server, or set the group appropriately (with appropriate group write permissions), or to set the permissiont to world writeable.

Commented:
same script, slightly modified and modernized.
you should really use the CGI-module!!

#!/usr/bin/perl
use CGI;
my $q=new CGI;

name,
comname,
add1,
phone1,
phone2
fax
email
comments

print $q->header;
print '<html><body bgcolor="#fcde9c">';

open (INFILE, ">> data.txt");
print INFILE $q->param("name") . " ? " .
  $q->param("comname") . ? " .
  $q->param("add1") . " ? " .
  $q->param("phone1") . " ? " .
  $q->param("phone2") . " ? " .
  $q->param("fax") . " ? " .
  $q->param("$email") . " ? " .
  $q->param("$comments") . "\n";
close(INFILE);                    

print  "<<MYHTML";
Thanks
<center><h1>Thanks for registering<br></h1></center>
To:  $name <BR>
From: Customer Support <support\@suretex.net><BR>
Subject: Welcome to suretex.net<BR><BR>
Dear $name,
Thank you for visiting suretex.net. It's a great pleasure to have you on board.<BR><BR>

You can feel the pleasure of having business with the SURETEX INC.,

Gurgaon .<BR>
             
If you have any further questions please feel free to contact our support team at: <a href=\"mailto:info\@suretex.net\">support\@suretex.net</a><BR>
Thanks again for visiting suretex.net. We look forward to satisfy all your needs!<BR><BR>
                               
Sincerely,<BR>

suretex.net Customer Support.
                                           
<br><br><br><br><br><font align=right>
<a href=../contact.htm><<<Back</a></font>
</body>
</html>
MYHTML
CERTIFIED EXPERT

Commented:
manu1076,

"... it give an error..."

What is the exact error that it gives? Can you post the URL of your web site, so that we can see the error ourselves?

Pl. provide as much more detail as you can. This will help you get a more accurate answer, faster.

Thanks,
CERTIFIED EXPERT

Commented:
manu1076,

Did you get the solution you were looking for?

What solution, if any, did you use?

Let us know.
CERTIFIED EXPERT

Commented:
manu1076,

                     Did you get the solution you were looking for?

                     What solution, if any, did you use?

                     Let us know.

Commented:
manu1076,
my script works fine on my local machine but when i upload it no longer works:

causes:
A:
devlopment machine is windows and live server is unix and you have no got rid of unix line endings.

happens all the time, this one, get your ftp to remove them or your editor to save the file as a unix type then upload it.

B:
you've uploaded it as a binary.. set the upload to auto in your ftp program, let it determine ehat is it..

C:
permissions are set so that your program hasa insufficient authority to execute..

peewee
Points for holli - http://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20282301

Sorry Asker chose not to finalize this, and thanks to Manesh, this was brought to our attention and points split.

Moondancer - EE Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.