You're absolutely right! you can use PHP but you can consider using jquery and get hold of the input element via $('input') and getting the value and adding the css.
Assuming you have an input with the id of #css, i'm going to use the on() method and use event delegation to target the particular id which in this case is #css.
You would do something like this:
$('form").on('submit', '#css', function()) {
var value = $this.val();
$('body').css('background-color', value);
});
You may want check the value you receive from your user and ensure that it is a proper css hex color value or something. Some form of validation.
This is just one of a few ways you can and PHP is also an option.
inputis part of a form, right? How is the form processed? Once you have the variable, you only need to change the style attribute of the body element. JavaScript might be enough for this.