How do I fix this: syntax error, unexpected ‘:’, expecting ‘)’

Your code:

$bg = (!$bgimage == '') ? 'style="background-image:url'("".$bgimage[url].'")' : '';

There’s a confusion with the quote marks. You’re closing your ' too early, but it’s really hard to see in a construction like this. (Also, the array index needs to be wrapped in quotes, either single or double.)

$bg = (!$bgimage == '') ? 'style="background-image:url("'.$bgimage['url'].'")' : '';

might clear up the PHP error, but I’m not sure it’ll still do what you want it to. There’s still some confusion with quote marks in the CSS; also, is $bgimage a string or an array?

I’d recommend not using the ternary operator, in this case, to make the code more readable.

$bg = '';
if ( ! empty( $bgimage ) ) {
    $bg = 'style="background-image:url(\'' . $bgimage['url'] . '\')";
}