The D5100 has a better performing image sensor, particularly at high ISO settings which are used in low light situations. DxOMark - Compare cameras side by side
Which camera to choose depends on how you will use it.
They are both great DSLR's. But the D5100 is a higher level than the D3100.They both take amazing pictures so you really can't go wrong! If you can spend 800$, you can get a D5100, or a D3100 and use the extra to buy another lens with it.
I'm a beginner and I just bought the D5100 and I love it. I don't think it matters if you are a beginner or not. It all depends on what you want and need.