It's not a very logical saying if you ask me...
Surely it's better to live a good and full life (regardless of religion) and if there is a hereafter, then that's all gravy....
....than to forgo and sacrifice now (as most religions demand) in the hope of a better life that may or may not exist?
Neat trick to keep the hoi polloi from complaining and rebelling mind you.
Also how will you 'know' there is no God when you're dead and there's no afterlife?