Fix undefined index on $name

If condition isn't met the $name variable isn't set, resulting in an undefined index.