trying to take code from MySQL and use as CSS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daj
Forum Newbie
Posts: 5
Joined: Sat Feb 20, 2010 1:43 pm

trying to take code from MySQL and use as CSS

Post by daj »

Hi all

I am trying, and failing, to provide CSS code to the headers on an HTML page.

The CSS is typed and saved into an SQL database using the mysql_real_escape_string and htmlspecialchars functions.

I then want to pull this back as part of the HTML header section, example...

Code: Select all

<link rel="stylesheet" type="text/css" media="screen" href="raw.php?p=test2"  />
the raw.php file reads the 'p' parameter and extracts the 'test2' entry from SQL and echo's it.

Code: Select all

$result = mysql_query($page_qry);
$row = mysql_fetch_array($result);
if ($row) 
    {
        echo htmlspecialchars_decode($row['content']);
    }
The problem is that the HTML page does not use the CSS echo'd by my PHP code. If I refer to one of the classes defined in the CSS is is ignored by the HTML.

If I simply visit the page ... raw.php?p=test2 the results look fine

I must be missing something. :banghead:

any thoughts?

thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: trying to take code from MySQL and use as CSS

Post by requinix »

As far as the browser is concerned, you pointed it to an HTML page. Why? Because the server told it so.

Code: Select all

header("Content-Type: text/css");
Put that right at the top of the script, before anything has been outputted.
daj
Forum Newbie
Posts: 5
Joined: Sat Feb 20, 2010 1:43 pm

Re: trying to take code from MySQL and use as CSS

Post by daj »

Excellent, worked perfectly. I knew I was missing something

thank you
Post Reply