Form validation of the pattern if(empty($fname)) is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation.
Form validation has been covered a zillion times in this forum - try using the search feature. Come back if you are still having problems.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.