Sounds like it could be a bad battery. If the phone works when plugged in, does it show a charging symbol? Download the app "Ampere" from the play store. Plug in your phone and start the app. It will measure the current that your phone is taking, and will also give you the status of your battery.
If your phone restarts when you unplug it, then there is obviously something shorting out in the battery that's making the phone lose power.
If you are able to get your hands on another battery, try that. How old is the phone? If it's still under warranty, you can get a new battery.