I simplified the condition from if($check==1)  to  if (!($userExist))