CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Wierd CGI header error

 



seth_h
New User

Dec 18, 2003, 9:36 PM

Post #1 of 4 (567 views)
Wierd CGI header error Can't Post

I'm pulling my hair out so any help is very much appreciated. Here's the scenario:

I have a fully functional perl CGI script that connects to a MySQL database, using DBI, which outputs a list of all records found. (Extremely bare-bones) When I call this script with a web browser it outputs all records as expected. When I run it locally from a command prompt, it also works fine. Here's the catch. When I modify the statement to connect to an Access database, and not the MySQL, using an ODBC driver, I get an error in my browser that says : CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers.



If I run the .cgi script from a DOS prompt, though, everything looks fine. I get the proper "Content-type: text/html" header, and all records are returned as they should be. Bear in my mind, I haven't changed the rest of the script at all from the original. Why would the script work from the DOS prompt, but not when loaded in a browser? Below is the ONLY modification made in my script:



This one works (MySQL)

$dbh = DBI-> connect ("DBI:mysql:host=localhost;database=cars", "Maintenance", "password",{PrintError => 0, RaiseError => 1});



This one does not (Access-ODBC)


$dbh = DBI-> connect ("DBI:ODBC:CarData", {PrintError => 0, RaiseError => 1});



I think that some kind of error is kicking out before the header is output to the web, but this error doesn't happen when run locally. The printout looks PERFECT in a DOS window so I don't get why it's bombing out through a browser. I am running IIS 6.0 with the latest installation of ActivePerl from ActiveState. Please let me know if you need any further info at all. Thanks SOOOOOOO much for any help.

--Seth


davorg
Thaumaturge / Moderator

Dec 19, 2003, 1:45 AM

Post #2 of 4 (566 views)
Re: [seth_h] Wierd CGI header error [In reply to] Can't Post

The problem is almost certainly that the CGI program is returning an error message _before_ the CGI headers. See Suffering from Buffering for a more detailed description of the problem.

Try putting

Code
$|++;

near the top of the program to turn off buffering. Also look in the web server error logs to see what the real error is.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


seth_h
New User

Dec 19, 2003, 9:37 AM

Post #3 of 4 (561 views)
Re: [davorg] Wierd CGI header error [In reply to] Can't Post

That didn't seem to do the trick. On another forum they suggested that I change my DBI declaration to the following:

$dbh = DBI-> connect ("DBI:ODBC:CarData", {PrintError => 1, RaiseError => 1});

which resulted in the following when run from a command prompt.

C:\cgi-bin>perl returnauction.cgi
[Fri Dec 19 12:30:16 2003] returnauction.cgi: Can't modify constant item in scal
ar assignment at returnauction.cgi line 7, near ");"
[Fri Dec 19 12:30:16 2003] returnauction.cgi: Execution of returnauction.cgi abo
rted due to compilation errors.

C:\cgi-bin>

When I do that I get the following error. Any idea why?

Thanks again for your help.

--Seth


davorg
Thaumaturge / Moderator

Dec 20, 2003, 9:25 AM

Post #4 of 4 (555 views)
Re: [seth_h] Wierd CGI header error [In reply to] Can't Post

I don't believe I suggested anything that would fix your problem. I made a suggestion that would make it simpler to work out what the problem is.

Without seeing more of the code (like line 7 for example) it's very hard to be any more help.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives