How to add in <style> CSS php echo

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts: 261
Location: Holland Rotterdam

How to add in <style> CSS php echo

Dear Coursesweb, Hope you do all fine

I can not find out how to add in the <style> a result from my database.
Hope to get some support for this. `thanks`

Code: Select all

<?php 
include('../connection1.php');

$id = (int) $_GET['id'];

$sql=mysqli_query($connmaker,"SELECT * FROM `maker` WHERE post_id='" . $id . "' ");
$users=mysqli_fetch_assoc($sql);
?>

<style>
body {
  font-family: "Exo 2", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  background: <?php echo $users['bbgcolor'];?>;
  min-height: 100vh;
}
</style>

MarPlo
Hello,
Try the followig code:

Code: Select all

<?php 
include('../connection1.php');

$bgc_user ='green';   // default color

if(isset($_GET['id'])) $id = (int) $_GET['id'];
else $id =1;

$result= mysqli_query($connmaker, "SELECT * FROM maker WHERE post_id=". $id);
while($row = mysqli_fetch_assoc($result)){
  $bgc_user = $row['bbgcolor'];
}
?>

<style>
body {
  font-family: "Exo 2", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  background: <?php echo $bgc_user; ?>;
  min-height: 100vh;
}
</style>
- If the color is in hex code, add # before it (ex.: background: #aabcfe;).

JanMolendijk
O GOD THANKS MARPLO

When I`m home I gonna try the code

So much thanks for this support