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

Hi looking for some help. And I have RTFM and searched the web!!
Server W2K with Perl and Mysql installed - only FTP access. Created a mysql table and can get some output to the screen by trying to format it in a table (see www.hcresources.co.uk/query1.pl for example).
I have read notes here suggesting use of HTML::Template or DBIx::XHTML_Table. I have tried these (with the examples provided) but I get no output to my browser. How can I run queries against the remote server to see what is installed without having direct access. I have seen lots of scripts that suggest how to do things but they never produce any output on my browser. I do not know if it is because the modules are not installed on the server or I am not formatting the information correctly.
I did go and try to buy Perl and Mysql on the web by Paul Dubois as recommended here but it was out of stock and I did not know if it was too advanced for me anyway.

An example I have tried is
#!D:\Perl\bin\perl.exe #test4.pl use warnings; use strict; print "Content-type: text/html\n\n"; perl -MCPAN -e 'for $mod (CPAN::Shell->expand("Module","/./")) { next unless $mod->inst_file; print $mod->id," ", $mod->inst_version, + "\n"; }';

Looking for some help
Regards John

Replies are listed 'Best First'.
Re: Trying to output mysql query to browser
by moodster (Hermit) on Jan 31, 2002 at 22:15 UTC
    Well, for starters your code looks really weird. The 'perl -MCPAN -e...' statement is usually just something you use when installing or modifying the perl modules/libraries on you server. So that doesn't really belong in a cgi script.

    As far as I can tell, I get some output from the script at the URL you specified, but it looks like the Content-type is all wrong. You got it right in your example, though.

    I haven't read it personally, but I'm told that Ovid's Web Programming Course is a good place to start. You should play around with the basic stuff like CGI.pm and creating a few forms first. When you feel comfortable with that you can start worrying about databases and DBIx::XHTML_Table and stuff.

    Cheers,
    -- moodster

Start Simple Before - Trying to output mysql query to browser
by metadoktor (Hermit) on Jan 31, 2002 at 22:41 UTC
    First of all, have you done any CGI programming before? If not, then start out with a very very simple example or learn to use CGI if you don't feel comfortable with the not so esoteric art of CGI programming.

    IMPORTANT! Before you run that CGI script of yours on the web first try to run it from your command line prompt like so:

    C:\> perl -w mycgiscript.pl
    If you get NO ERRORS and you get the output that you're expecting then you can try invoking your CGI script from a browser.

    You should start out using something simple like this:

    #!D:\Perl\bin\perl -wT use strict; print "Content-Type: text/html\n\n"; print "<html><body>\n"; print "Hello World!\n"; print "</body></html>\n";

    And gradually add a SQL query or whatever and you'll obviously want to make sure that you output correct HTML which would include the DOCTYPE header.

    Also, don't forget about SECURITY. Be careful in what you accept from the browser, if anything.

    metadoktor

    "The doktor is in."

      Thanks to everybody for those comments, most helpful
      I do not want to run before I can walk but I also want to produce my web page as quickly as possible and then learn a bit more afterwards.
      I have checked out Ovid's course and that looks good so I will spend a bit of time on that.
      Thanks again for your time, I am sure you will hear from me again
      John
Re: Trying to output mysql query to browser
by talexb (Chancellor) on Jan 31, 2002 at 22:11 UTC
    Try adding a <table> at the beginning your HTML output .. that would probably help. It's also a nice idea to put line endings here and there so that the code doesn't come out as a single line of text. This is handy when debugging more than anything else.

    --t. alex

    "Of course, you realize that this means war." -- Bugs Bunny.