title: Dynamic CSS with PHP based on database
body: <p>found a couple answers here on StackOverflow and used them as my models, but I must be missing something.  I'm trying to set a couple of background colors dynamically in CSS based on what is in my database, but it's not working - when I check Inspect Element in Chrome, background-color has a line through it and a warning mark for 'Invalid property value'.</p>
  
  <p>Here's my code; it's in two separate files - the first is in the header include file, and the second is in the linked .php / css-esque file.</p>
  
  <p>Header include: [Edited 4/29 to include session code]</p>
  
  <pre><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-&gt;query($sql) or die(mysqli_error());
  $row = $result-&gt;fetch_assoc();
  $colorOne = '#' . $row['colorone'];
  $colorTwo = '#' . $row['colortwo'];
  $carrierLogo = '/companylogos/' . $row['logo'];
  </code></pre>
  
  <p>PHP/CSS file:</p>
  
  <pre><code>&lt;?php header("Content-type: text/css"); 
  
  ?&gt;
  
  #main {
      width: 85%;
      margin: 0 auto;
      padding: 0.75em 0;
  }
  
  #colorOne {
      width: 100%;
      height: 12px;
      background-color: &lt;?php echo $colorOne; ?&gt;;
  }
  
  #colorTwo {
      width: 100%;
      height: 7px;
      background-color: &lt;?php echo $colorTwo; ?&gt;;
  }
  </code></pre>
  
  <p>EDIT 4/29:</p>
  
  <p>This is the CSS generated:</p>
  
  <pre><code>#main {
      width: 85%;
      margin: 0 auto;
      padding: 0.75em 0;
  }
  
  #colorOne {
      width: 100%;
      height: 12px;
      background-color: ;
  }
  
  #colorTwo {
      width: 100%;
      height: 7px;
      background-color: ;
  }
  </code></pre>
  
  <p>I also echoed the variable back in the html so I know that there should be something in the variable.  Should I be opening the database  and assigning the variable inside the css.php file?</p>
  
  <p>CSS/PHP is linked this way in header:</p>
  
  <pre><code>&lt;link type="text/css" rel="stylesheet" href="../css/carrier.php"&gt;
  </code></pre>