This should also work: header("Location: view_{$galleryName}_images.php");. The problem is that it is greedy when dereferencing the variable, so it doesn't know where your variable name ends. It considered your entire variable to be all valid chars, so it was attempting to resolve $galleryName_images as your variable name.
Always enable your error reporting in development domain (even inline will suffice):