php条件连接不起作用

So for some reason I need to check whether password should change or not. for that I use a variable to see if it's true or false.

$query  = "UPDATE c_users SET ";
$query .= ($changepass) ? "user_pass = '$password', " : '' . "user_email = '$email', user_role = $role, display_name = '$nick', WHERE ID = $id";

echo $query . "<br>";

This works fine if ($changepass) is false and if I print it:

UPDATE c_users SET user_email = 'example@example.com', user_role = 3, display_name = 'ROBOT', vip_status = 1 WHERE ID = 550

however if ($changepass) is true, it doesn't work as expected. It should append user_pass = '$password', to rest of the statement but instead it prints this:

UPDATE c_users SET user_pass = '$2y$10$l1TylEhM2oz4WdmlwWkcaupjpj1tt/HCyn7XGWbep1judDQb3E7e.',

notice that rest of the statement is missing. so query fails. how to fix it?

That's because your ternary is effectively:

if ($changepass) {
    $query .= "user_pass = '$password', ";
} else {
    $query .= '' . "user_email = '$email', user_role = $role, display_name = '$nick', WHERE ID = $id";
}

So it never appends the additional set values if $changepass is true

To achieve what you want, you need to do

$query .= ($changepass) ? "user_pass = '$password', " : '';
$query .= "user_email = '$email', user_role = $role, display_name = '$nick', WHERE ID = $id";

But you really should be entering the 21st century and using prepared statements with bind variables in 2015