Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms: Works on UNIX doesn't work on Microsoft

Status
Not open for further replies.

jbs

Programmer
Feb 19, 2000
121
US
ok, now that I've got Perl working on my Microsoft Server I'm now able to run my Form program.&nbsp;&nbsp;Only problem is a slight bug.&nbsp;&nbsp;<br><br>What I would like to do is submit a form that has a 'lastname', 'password', and 'request' to a perl program which takes the users input and store it in a file that has a file name equal to the 'lastname' variable.<br><br>The output of the program as currently written is &quot;success11&quot; and it is stored in a file with the name of '1'.<br><br>clearly the cgi script is able to obtain the data from the form.<br><br>The script works in unix....can anyone help out here?<br><br>thanks very much....<br><br>Jerry<br><br><br>=============================<br><br>Here is the file &quot;example2.pl&quot; on the NT server:<br><br><br><br>&get_form_data;<br>print &quot;Content-type: text/html\n\n&quot;;<br><br>$file=&quot;$FORM{'lastname'}&quot;¦¦print &quot;Failed to assign $file,$!&lt;BR&gt;\n&quot;;<br>$password=&quot;$FORM{'password'}&quot;¦¦print &quot;Unable to assign<br>$password,$!&lt;BR&gt;/n&quot;;<br>$request=&quot;$FORM{'request'}&quot;¦¦print &quot;Unable to assign $password,$!&lt;BR&gt;/n&quot;;<br>open(OUT,&quot;&gt;$file&quot;)¦¦print &quot;Failed to open $file,$!&lt;BR&gt;\n&quot;;<br><br>print &quot;&lt;HTML&gt;\n&lt;BODY&gt;\n&quot;;<br>print &quot;&lt;/BODY&gt;\n&quot;;<br>print&quot;&lt;p&gt;Your data has been successfully sent to the web<br>server\n&lt;/p&gt;&quot;;<br>print OUT &quot;success&quot;;<br>print OUT $lastname;<br>print OUT $password;<br>print OUT $request;<br>close(OUT)¦¦print &quot;Failed to close $file, $!&lt;BR?\n&quot;;<br>exit;<br><br><br>sub get_form_data<br>{<br>&nbsp;&nbsp;#Get the input<br>&nbsp;&nbsp;read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );<br>&nbsp;&nbsp;#Split the name-value pairs<br>&nbsp;&nbsp;@pairs = split(/&/, $buffer);<br>&nbsp;&nbsp;foreach $pair (@pairs)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;($name, $value) = split(/=/, $pair);<br>&nbsp;&nbsp;&nbsp;&nbsp;# Un-webify plus signs and %-encoding<br>&nbsp;&nbsp;&nbsp;&nbsp;$value =~ tr/+/ /;<br>&nbsp;&nbsp;&nbsp;&nbsp;$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;<br>&nbsp;&nbsp;&nbsp;&nbsp;$value =~ s/&lt;v!--(.¦\n)*--&gt;//g;<br>&nbsp;&nbsp;&nbsp;&nbsp;$FORM{ $name } = $value;<br>&nbsp;&nbsp;}<br>}<br><br><br>Here is HTML program that references the above CGI file:<br><br><br>&lt;html&gt;<br><br>&lt;head&gt;<br>&lt;meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot;&gt;<br>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;&gt;<br>&lt;meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;&gt;<br>&lt;meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;&gt;<br>&lt;title&gt;New Page 1&lt;/title&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br><br>&lt;form method=&quot;POST&quot; action=&quot;cgi-bin/example2.pl&quot;&gt;<br>&nbsp;&nbsp;&lt;p&gt;Lastname: &lt;input type=&quot;text&quot; name=&quot;lastname&quot; size=&quot;20&quot;&gt;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;Password: &lt;input type=&quot;text&quot; name=&quot;password&quot; size=&quot;20&quot;&gt;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;Request:&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;text&quot; name=&quot;request&quot; size=&quot;20&quot;&gt;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt; &lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;&gt;&lt;input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;&gt;&lt;/p&gt;<br>&lt;/form&gt;<br><br>&lt;/body&gt;<br><br>&lt;/html&gt;<br><br>
 
I've done more work on this and still can't get it to work in Microsoft IIS with latest active perl installed (work fine on a unix server).&nbsp;&nbsp;<br><br>I've added some better error descriptions in the code to help the process.<br><br>The program should accept data from the user via a web page, write the data to a file, then send a new web page back to the user announcing a success.<br><br>The filename that is created should equal the contents of the 'lastname' that is entered on the form.<br><br>The program seems unable to receive the data entered into the form, the data then seems to default to a value of one...then a file is created with the name of '1' and the other two values from the form are also entered as '1' into the text file.&nbsp;&nbsp;Also, web user doesn't get a nice new web page to look at.<br><br>I'm user a single work station to run IE to access the web page and enter the data; hence there shouldn't be any network problems.<br><br>Still stuck but trying on my own...<br><br>Can anyone take a quick look and provide advice?<br><br>thanks/ Jerry<br><br>====== contents of the file output file named &quot;1&quot;&nbsp;&nbsp;======<br><br>&quot;success transmission11&quot;<br><br>(notice the 11 on the end.&nbsp;&nbsp;This seems to be the value Perl is using for the form input vice the real text input.&nbsp;&nbsp;This does work on unix....strange).<br><br>======&nbsp;&nbsp;contents of the perl file called &quot;example4.pl&quot;&nbsp;&nbsp;====<br><br>&get_form_data;<br>print &quot;Content-type: text/html\n\n&quot;;<br><br>$file=&quot;$FORM{'lastname'}&quot;¦¦print &quot;Failed to assign file name $file,$!&lt;BR&gt;\n&quot;;<br>$password=&quot;$FORM{'password'}&quot;¦¦print &quot;Unable to assign password $password,$!&lt;BR&gt;/n&quot;;<br>$request=&quot;$FORM{'request'}&quot;¦¦print &quot;Unable to assign request $password,$!&lt;BR&gt;/n&quot;;<br>open(OUT,&quot;&gt;c:$file&quot;)¦¦print &quot;Failed to open $file,$!&lt;BR&gt;\n&quot;;<br><br>print &quot;&lt;HTML&gt;\n&lt;BODY&gt;\n&quot;;<br>print &quot;&lt;/BODY&gt;\n&quot;;<br>print&quot;&lt;p&gt;Data successfully sent to the web server\n&lt;/p&gt;&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>print OUT &quot;success transmission&quot;;<br>print OUT $lastname;<br>print OUT $password;<br>print OUT $request;<br>close(OUT)¦¦print &quot;Failed to close $file, $!&lt;BR&gt;\n&quot;;<br>exit;<br><br><br>sub get_form_data<br>{<br>&nbsp;&nbsp;#Get the input<br>&nbsp;&nbsp;read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );<br>&nbsp;&nbsp;#Split the name-value pairs<br>&nbsp;&nbsp;@pairs = split(/&/, $buffer);<br>&nbsp;&nbsp;foreach $pair (@pairs)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;($name, $value) = split(/=/, $pair);<br>&nbsp;&nbsp;&nbsp;&nbsp;# Un-webify plus signs and %-encoding<br>&nbsp;&nbsp;&nbsp;&nbsp;$value =~ tr/+/ /;<br>&nbsp;&nbsp;&nbsp;&nbsp;$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;<br>&nbsp;&nbsp;&nbsp;&nbsp;$value =~ s/&lt;v!--(.¦\n)*--&gt;//g;<br>&nbsp;&nbsp;&nbsp;&nbsp;$FORM{ $name } = $value;<br>&nbsp;&nbsp;}<br><br>}<br><br>====== contents of HTML file that calls example4.pl ======<br><br>&lt;html&gt;<br><br>&lt;head&gt;<br>&lt;meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot;&gt;<br>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;&gt;<br>&lt;meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;&gt;<br>&lt;meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;&gt;<br>&lt;title&gt;New Page 1&lt;/title&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br><br>&lt;form method=&quot;POST&quot; action=&quot;cgi-bin/example2.pl&quot;&gt;<br>&nbsp;&nbsp;&lt;p&gt;Lastname: &lt;input type=&quot;text&quot; name=&quot;lastname&quot; size=&quot;20&quot;&gt;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;Password: &lt;input type=&quot;text&quot; name=&quot;password&quot; size=&quot;20&quot;&gt;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;Request:&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;text&quot; name=&quot;request&quot; size=&quot;20&quot;&gt;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;&nbsp;&lt;/p&gt;<br>&nbsp;&nbsp;&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submit&quot;&gt;&lt;input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;reset&quot;&gt;&lt;/p&gt;<br>&lt;/form&gt;<br><br>&lt;/body&gt;<br><br>&lt;/html&gt;<br>
 
Problem Solved!<br><br>IIS configuration problem. <br>
 
Could you let us know what the problem was? It sounds like the kind of thing people are going to come up against time and time again. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"
 
Not a problem...I think it will be useful for others.&nbsp;&nbsp;<br><br>Right now I'm building another Microsoft web server that will run Perl and ASPs.&nbsp;&nbsp;I'm writing down the steps plus what I did wrong the 1st time.&nbsp;&nbsp;I'll post it as a separate thread in the ASP & Perl areas (I had postings in both areas last week).<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top