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

I want to be able to dynamically set the CSS styles, using the contents of a table in a MySQL database. It was suggested by a friend that I do something like this inside my HTML file:
<link rel="stylesheet" type="text/css" href="skins/stylesheet.cgi?skin +=1" title="1" />
and I've managed to create stylesheet.cgi, and have it get the stylesheets out of the parameters passed to it...the question is, how am I supposed to get it to set the value of stylesheet.cgi's $content to the stylesheet? I've tried having stylesheet.cgi print out the stylesheet information at the end, but to no avail.

Thanks in advance,
Spidy

Replies are listed 'Best First'.
Re: Interesting CSS/CGI issue...
by sauoq (Abbot) on Sep 24, 2005 at 06:32 UTC
    the question is, how am I supposed to get it to set the value of stylesheet.cgi's $content to the stylesheet?

    I don't understand this question. Context might help. Perhaps you should post some code.

    I've tried having stylesheet.cgi print out the stylesheet information at the end, but to no avail.

    Well, that's exactly what you should do. You should also print the correct content-type header. Start simple and work your way up. This might get you started:

    #!/usr/bin/perl use warnings; use strict; print "Content-type: text/css\n\n"; print <<END_CSS; body { color: red; } END_CSS
    -sauoq
    "My two cents aren't worth a dime.";
    
      Well, here's stylesheet.cgi:
      #!/usr/bin/perl -w # # #error reporting modules use strict; #CGI modules use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); #database modules use DBI; my $query = new CGI; my $id = $query->param('skin'); my $content = ''; my $sth = ''; my $dbh = DBI->connect("DBI:mysql:****","****","****") or die("Error connecting to MySQL Database: $DBI::errstr\n"); $content = $dbh->selectrow_array("SELECT content FROM skins WHERE id = + $id"); print "Content-type: text/css\n\n"; print qq ~ $content ~;

      Which still doesn't work. It's printing out $content all right, and that's all working...but when I try to use that line of HTML, nothing happens.
      (the content for the first skin is just .body{background-color: #00FF00;})

        Is your server properly configured to run CGI scripts? You might try temporarily changing your content type to text/plain and hitting the script from your browser.

        -sauoq
        "My two cents aren't worth a dime.";
        
Re: Interesting CSS/CGI issue...
by Spidy (Chaplain) on Sep 24, 2005 at 06:45 UTC
    Aghr...as it turns out, the issue was the period before "body" in my CSS. :S

      Ah, yep. That'd do it. Easy to miss that. Glad you got it working.

      -sauoq
      "My two cents aren't worth a dime.";