Niy has asked for the wisdom of the Perl Monks concerning the following question:

My script works well in command line, but browser can not see the ouput from the database. The following is script:
#!E:/users/yin/perl/bin print "Context-type text/html\n\n"; print "THis is try for DBI module\n"; use DBI; $dbh=DBI->connect('dbi:ODBC:db1'); $sqlstatement="SELECT Field1 FROM Customers"; $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQl statement, maybe invalie?" +; while (@row=$sth->fetchrow_array) { print "@row\n"; }
In the command line, the output:
Context-type text/html THis is try for DBI module Frog Jameson Gold
But in browser, I only can see:
THis is try for DBI module
The output from the database disappears, anyone helps? Thanks in advance.

Replies are listed 'Best First'.
Re (tilly) 1: why browser can not see?
by tilly (Archbishop) on Feb 17, 2001 at 01:48 UTC
    Why do you have a Context-type of text/html?

    Make that a Content-type of text/plain and see if your output doesn't look a little better.

      And remember to add a colon after "Content-type" so that the browser will recognize it as an HTTP keyword.

        Several months ago some monks advised me to start using CGI.pm, which is built in to current versions of Perl. One thing which CGI.pm does very well is producing the http header and boilerplate HTML required for displaying output. In this case, using CGI.pm would have solved the part of the problem caused by the typo in the http header.

        To use CGI.pm add:

        use CGI qw/:standard/; print header, start_html('A Simple Example');
        Then add your application-specific HTML. End your page with the statement
        print end_html;

        A programmer named Lincoln D. Stein who approaches Larry-hood in his good works wrote this module. You can read his documentation for it here.

Re: why browser can not see?
by eg (Friar) on Feb 17, 2001 at 01:34 UTC

    (This ought to be in Seekers of Perl Wisdom).

    The problem is that you're not checking for errors. The connect is probably failing because the webserver doesn't have permission to access your database. Give it a username/password to use and check for errors!

      And, of course, -w/use strict - do it now before the the script gets any bigger. You'll be much happier down the road ...

      a

Re: why browser can not see?
by Anonymous Monk on Feb 23, 2001 at 01:17 UTC
    What kind of right server have? I set a passwd for database, and make corresponding change in code, but browser still can't see. I think this direction is correct: server may have different right as user who can execute in command windows. BTW, I use MS Access