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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi script asking for more info then HTML sends

Status
Not open for further replies.

random260

Programmer
Mar 11, 2002
116
US
I have a few HTML forms that submit the collected info to a .cgi, which then sends the info on via sendmail. Everything was working fine until I switched hosting, and I started get 500 "premature end of script header" errors. After beating my head against the wall for a few days I discovered that my previous host's version of perl, sendmail, whatever, did not care if the HTML didn't have all the params the .cgi asked for - for example, if my HTML had

field1
field2

and my .cgi had

param("field1")
param("field2")
param("field3")

the script and sendmail worked with no errors. But I have several HTML forms that all point to the same .cgi file. The .cgi file asks for up to field20, and some of the HTML forms have only up to field13. Thus, I get the "premature end of script" error unless the form has up to field20. Do I have to write a separate script for each form on this host, or is there a line of code I can put in the .cgi script that will tell it to ignore if the field doesn't exist so I don't get that error? Maybe something that can be done with if exist()?

Thanks!
Steve
 
You should not have to re-write anything. If it work on another server then it will work on your current. PERL is extremely portable.

This sounds more like a configuration problem. Lets see some code, so we can help.

also try putting this into your script for debugging.

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

right below this line,
#!/usr/bin/perl

this may help you figure out the problem.


haunter@battlestrata.com
 
If your perl script is trying to assign the param values to variables and there is no "param", then there is a good chance that the script will fail. Easiest thing is to add hidden input fields to your html pages so that all pages have the same number of input fields. Then, for those hidden input fields, assign each a value of " " (1 space). Then your sript will be able to assign those params with a valid value.

There's always a better way...
 
Reply to Haunter;
I agree that perl is very portable, but there is definately no code problem - I've been the whole debugging route and traced the problem back to this. The script DOES work on one server even with the extra parms, and does NOT work on the second one. I can make it work on the second one by removing the extra parms, they are definately the problem - I remove those, it works fine. I have the script set to display errors to the screen, I have full access to the logs, and have included several variations of the line you suggested putting in to prevent anything being printed before the header, and everything I do, read, research, etc. says these parms are the problem.

Reply to tviman;
Ya, I considered that, or even just writing the script for the largest one and chopping out the extra parms and assigning each form it's own version of the script. Problem is, some of these new forms coming up will vary from 20 to 120 fields - and it will be a real pain to put in that many hidden fields to an html doc, or edit that much out of the script (although would be easier in the script if written correctly). Even a line of code that would kick perl out of a loop when it enountered an invalid parm without causing a 500 error would help - anything to save me having to re-write everything lol.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top