Use the below code to show the error message:
if (fieldname == null){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,’Please enter value’));
return null;
}
Insert the below tag inside the visualforce page within page block
<apex:pageMessages ></apex:pageMessages>