Page 1 of 1

trying to take code from MySQL and use as CSS

Posted: Sat Feb 20, 2010 1:56 pm
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

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

Posted: Sat Feb 20, 2010 2:17 pm
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.

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

Posted: Sat Feb 20, 2010 3:26 pm
by daj
Excellent, worked perfectly. I knew I was missing something

thank you