Dynamic CSS with database-based PHP

found a couple of answers here on StackOverflow and used them as my models, but I have to miss something. I am trying to set a couple of background colors dynamically in CSS based on what is in my database, but it does not work - when I check the Inspect Element element in Chrome, the background color has a line through it and a warning sign for "Invalid property value.

Here is my code; it consists of two separate files: the first in the header file, and the second in the associated .php / css-esque file.

The title includes: [Edited 4/29 to include session code]

session_start();
// check if $_SESSION was set before
if (!isset($_SESSION['email'])) {
header("Location: bad_login.php");
exit();
}

$_SESSION['companyid'] = $_POST['companyid'];
$companyID = $_SESSION['companyid'];
$email = $_SESSION['email'];

require_once('../includes/_connection.inc.php'); 
$connect = dbConnect('read');
$sql = 'SELECT colorone, colortwo, logo
        FROM companies
        WHERE companyid = ' . $companyID;
$result = $connect->query($sql) or die(mysqli_error());
$row = $result->fetch_assoc();
$colorOne = '#' . $row['colorone'];
$colorTwo = '#' . $row['colortwo'];
$carrierLogo = '/companylogos/' . $row['logo'];

PHP / CSS file:

<?php header("Content-type: text/css"); 

?>

#main {
    width: 85%;
    margin: 0 auto;
    padding: 0.75em 0;
}

#colorOne {
    width: 100%;
    height: 12px;
    background-color: <?php echo $colorOne; ?>;
}

#colorTwo {
    width: 100%;
    height: 7px;
    background-color: <?php echo $colorTwo; ?>;
}

EDIT 4/29:

This is the generated CSS:

#main {
    width: 85%;
    margin: 0 auto;
    padding: 0.75em 0;
}

#colorOne {
    width: 100%;
    height: 12px;
    background-color: ;
}

#colorTwo {
    width: 100%;
    height: 7px;
    background-color: ;
}

html, , -. css.php?

CSS/PHP :

<link type="text/css" rel="stylesheet" href="../css/carrier.php">
+4
2

.css .php

html : .php?

<link rel='stylesheet' type='text/css' href='css/style.php' />

style.php add

<?php
    header("Content-type: text/css; charset: UTF-8");
?>

, :

Edit:

session_start();, ( , , css/carrier.php, , $companyID = $_SESSION['companyid']; $email = $_SESSION['email'];).

?

        <?php
    session_start();
        header("Content-type: text/css; charset: UTF-8");
    $_SESSION['companyid'] = $_POST['companyid'];
    $companyID = $_SESSION['companyid'];
    $email = $_SESSION['email'];

    require_once('../includes/_connection.inc.php'); 
    $connect = dbConnect('read');
    $sql = 'SELECT colorone, colortwo, logo
            FROM companies
            WHERE companyid = ' . $companyID;
    $result = $connect->query($sql) or die(mysqli_error());
    $row = $result->fetch_assoc();
    $colorOne = '#' . $row['colorone'];
    $colorTwo = '#' . $row['colortwo'];
    $carrierLogo = '/companylogos/' . $row['logo'];
    ?>

#main {
    width: 85%;
    margin: 0 auto;
    padding: 0.75em 0;
}

#colorOne {
    width: 100%;
    height: 12px;
    background-color: <?php echo $colorOne; ?>;
}

#colorTwo {
    width: 100%;
    height: 7px;
    background-color: <?php echo $colorTwo; ?>;
}
+4

yesitsme . , , , , "" CSS .css.

, CSS? , , , , script.

CSS fwrite() , PHP , CSS, BDD, .

0

All Articles