Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:26:36+00:00 2026-06-15T23:26:36+00:00

I have the following PHP code which should load the data from a CSS

  • 0

I have the following PHP code which should load the data from a CSS file into a variable, search for the old body background colour, replace it with the colour from a submitted form, resave the CSS file and finally update the colour in the database.
The problem is, str_replace does not appear to be replacing anything.

Here is my PHP code (stored in “processors/save_program_settings.php”):

<?php
require("../security.php");

$institution_name = mysql_real_escape_string($_POST['institution_name']);
$staff_role_title = mysql_real_escape_string($_POST['staff_role_title']);
$program_location = mysql_real_escape_string($_POST['program_location']);
$background_colour = mysql_real_escape_string($_POST['background_colour']);
$bar_border_colour = mysql_real_escape_string($_POST['bar_border_colour']);
$title_colour = mysql_real_escape_string($_POST['title_colour']);

$url = $global_variables['program_location'];

$data_background = mysql_query("SELECT * FROM sents_global_variables WHERE name='background_colour'") or die(mysql_error());
$background_output = mysql_fetch_array($data_background);
$css = file_get_contents($url.'/default.css');
$str = "body { background-color: #".$background_output['data']."; }";
$str2 = "body { background-color: #".$background_colour."; }";
$css2 = str_replace($str, $str2, $css);

unlink('../default.css');
file_put_contents('../default.css', $css2);

mysql_query("UPDATE sents_global_variables SET data='{$institution_name}' WHERE name='institution_name'") or die(mysql_error());
mysql_query("UPDATE sents_global_variables SET data='{$staff_role_title}' WHERE name='role_title'") or die(mysql_error());
mysql_query("UPDATE sents_global_variables SET data='{$program_location}' WHERE name='program_location'") or die(mysql_error());
mysql_query("UPDATE sents_global_variables SET data='{$background_colour}' WHERE name='background_colour'") or die(mysql_error());
mysql_query("UPDATE sents_global_variables SET data='{$bar_border_colour}' WHERE name='bar_border_colour'") or die(mysql_error());
mysql_query("UPDATE sents_global_variables SET data='{$title_colour}' WHERE name='title_colour'") or die(mysql_error());

header('Location: '.$url.'/pages/start.php?message=program_settings_saved');
?>

Here is my CSS (stored in “default.css”):

@charset "utf-8";
/* CSS Document */

body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: #000;
}
body {
    background-color: #CCCCFF;
}
.main_table th {
    background:#003399;
    font-size:24px;
    color:#FFFFFF;
}
.main_table {
    background:#FFF;
    border:#003399 solid 1px;
}
.subtitle {
    font-size:20px;
}
input#login_username, input#login_password {
    height:30px;
    width:300px;
    font-size:24px;
}
input#login_submit {
    height:30px;
    width:150px;
    font-size:16px;
}
.timetable_cell_lesson {
    width:100px;
    font-size:10px;
}
.timetable_cell_tutorial_a, .timetable_cell_tutorial_b, .timetable_cell_break, .timetable_cell_lunch {
    width:100px;
    background:#999;
    font-size:10px;
}

I’ve run some checks using the following code in the PHP file:

echo $css . "<br><br>" . $str . "<br><br>" . $str2 . "<br><br>" . $css2; exit;

And it outputs (as you can see it’s not changing anything in the CSS):

@charset "utf-8"; /* CSS Document */ body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #000; } body { background-color: #CCCCFF; } .main_table th { background:#003399; font-size:24px; color:#FFFFFF; } .main_table { background:#FFF; border:#003399 solid 1px; } .subtitle { font-size:20px; } input#login_username, input#login_password { height:30px; width:300px; font-size:24px; } input#login_submit { height:30px; width:150px; font-size:16px; } .timetable_cell_lesson { width:100px; font-size:10px; } .timetable_cell_tutorial_a, .timetable_cell_tutorial_b, .timetable_cell_break, .timetable_cell_lunch { width:100px; background:#999; font-size:10px; }

body { background-color: #CCCCFF; }

body { background-color: #FF5719; }

@charset "utf-8"; /* CSS Document */ body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #000; } body { background-color: #CCCCFF; } .main_table th { background:#003399; font-size:24px; color:#FFFFFF; } .main_table { background:#FFF; border:#003399 solid 1px; } .subtitle { font-size:20px; } input#login_username, input#login_password { height:30px; width:300px; font-size:24px; } input#login_submit { height:30px; width:150px; font-size:16px; } .timetable_cell_lesson { width:100px; font-size:10px; } .timetable_cell_tutorial_a, .timetable_cell_tutorial_b, .timetable_cell_break, .timetable_cell_lunch { width:100px; background:#999; font-size:10px; }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:26:37+00:00Added an answer on June 15, 2026 at 11:26 pm

    I believe the problem might be that you’re trying to replace this:

    body {
        background-color: #CCCCFF;
    }
    

    by trying to find this in your CSS file:

    body { background-color: #CCCCFF; }
    

    The simplest solution on my opinion would be to just correctly format that line in CSS file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following lines of php code which should rename a file which
I have the following PHP code which works out the possible combinations from a
I have the following php code which I want to add a delay too:
I have the following piece of code which outputs a long article: <?php the_content();
I have the following code: <div><strong>Name: </strong><?php echo anchor('http://'.$link, $row->Name); ?></div> Which takes a
I have the following simple mysqli php application, which should work fine. $pk is
I have the following php code, which has been snipped for brevity. I am
I have the following code, which, upon the press of a certain button, should
I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>
I have the following PHP code, and for the life of me I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.