[Feature] PHP 7.0.x +
If you are using PHP 7.0.x+ you can use following syntax:
$background = $randombg ?? $_POST['bg'];
In this case $background
will get value from first variable which is set and is not null.
You can do even something like this:
$background = $randombg ?? $_POST['bg'] ?? 'No background given';
// if $randombg and $_POST['bg'] will be not set or null $background will become 'No background given'
More about that feature you can read in PHP RFC: Null Coalesce Operator and PHP: New Features
About your code
You have syntax in your code. More informations below:
if (isset($randombg)) {
$background = $randombg;
} else {
$background = $_POST['bg']) // you have syntax here, delete )
}
You can also use short syntax:
$background = (isset($randombg)) ? $randombg : $_POST['bg'];
And it works as follows:
$background = (condition) ? 'when true' : 'when false';
More about it you can read here (Shorthand if/else)