why do I always get an electric shock from my guitar when it's connected to my amp. I must wear sandals to play it or sit not touching the ground. Any solutions?
Tim basically has answered your question but I think this deserves larger type:
Your amp is trying to kill you!!!
Stop using it and get it replaced or repaired
This kind of problem is most common in older amps that have tube output stages. A tube output design for a guitar amp almost always requires an output transformer. The way the transformer is wired, it can have a large supply voltage on the primary windings. A strong enough impact to the amp can cause those windings to come into contact with the chassis of the amp and apply that voltage to the ground plane of the amp, which is connected to the guitar strings (normally that's a good thing). The other part of older amps is that they often have only a two-prong power cable, which means dangerous voltages that get into a ground plane are not bled off to earth.
NEVER cut the third pin off of a power cable or defeat the third pin in any way. Avoid using any high voltage equipment (which includes all kinds of amplifiers and especially tube equipment) that does not have a three prong cable.
It is possible that the wiring for the outlet you are plugging your amp into is bad. If the third prong is not connected to earth and the hot and neutral are not connected properly, a guitar amp (or anything connected to a microphone) can be a very dangerous thing to plug in.
An inexpensive outlet tester can save the life of a gigging musician.
Whenever you gig, test the outlets that you are plugging anything into and don't plug into anything that comes up bad. When you move into a new home, test your outlets and make sure they are good before plugging in your equipment.
In the 1970s, Kenny Rogers wrote a book about his experiences as a working musician and gave advice to anyone who wanted to be a professional musician. At the time of that writing, he noted that the number one cause of accidental death for a professional musician was electrocution (nope, not drugs, alcohol, or small planes). Times have changed since then as now we have three-prong power wiring for most equipment and fewer tube amplification stages that require very high supply voltages. Still, with all the power being used on a modern stage, the wise musician will be cautious.
One trick that will never get old is to avoid touching your guitar strings or microphone, get everything plugged in, and then try touching the guitar strings to the grill of the microphone (any mic, if you're not singing and playing). If you see any spark, something is very wrong and you could have died.
Adding to Todd's answer. Another problem that causes death to guitarists is a loose earth wire in the mains plug. Particularly on British type 3-pin plugs (an awful design!). Constant pulling on the flex causes the earth wire to come loose. No problem in itself, relatively. The amp still works. BUT when that earth wire flops about inside the plug, and touches the live pin, it's not what we expect. Most of us would say that the fuse will blow. It won't, as there is now no path to earth. Instead, the live is connected to the earth wire, connected to the chassis of the amp. Still all working happily, UNTIL - the guitarist touches his strings. Still no problem, standing on carpet, wood - or sandals. It's when he touches a 'proper' earth that the current flows from guitar through mic into the chassis of the p.a.- earthed conventionally. Or it could be a radiator. In between the hand on the guitar and the hand on the mic is a heart. Victim wants to let go, but electricity contracts muscles, making letting go of what's being held impossible. Death often ensues. TAKE CARE of equipment!
Todd's idea of touching strings to mic is better than mine - touch with the back of your hand, which won't grab if there's a problem. Not sure what'll be left of the mic/gtr though.
On the other hand (sic) it may just be static. How brave are you??
While your amp is in repair, get your house wiring checked. A working three-wire installation with a leak-current circuit breaker (which cuts the lines if the amount of current between the two live wires does not add up perfectly) will likely cut the power before you are getting fried.
It's not a full guarantee against heart failure but will stop you from being incinerated and helpers get a chance to attempt rescue and resuscitation without putting themselves into comparable amounts of danger. Also the circuit-breaking current is such that it's unlikely to incapacitate helpers as well as the victim him/herself.
A leak-current circuit breaker (they are called FI switch here) can be installed on your own power socket board where you plug in all amps. Strictly speaking, this does not protect agains dangerously high currents between two defective amps so if you want protection against being fried between mic and guitar or between two guitars, give every amp (together with its associated circuitry) its own FI switch.
Those switches will not usually engage at the kind of level that tingles (I have a laptop power supply here which I retired since it would buzz me whenever I brushed the firewire socket or other metal on my laptop. Highly annoying but never enough to throw the FI switch of the house which I know to be operative, and while the leak current was enough to light a power checking screw driver—by the way a device every musician should always carry in his case—it was not enough to give a reading on the voltmeter which has a finite input resistance).
The wiring is your life insurance. Whenever you use a socket for the first time, check the earth contact with your power-check screw driver. There is a non-zero number of mal-wired sockets in the world, and a live earth wire is the worst kind of sabotage. After switching the amps on, check their cases with the screw driver. A dead earth wire in sockets is the next worst culprit, and depending on your amp's way of dealing with the earth wire and possible capacitive leakage, it might show on the cases.
Next worst culprit is two-wire wiring in the house: this will render any house-level FI switch inoperative for a large number of use cases (namely anything involving touching the grounding on a device imagining itself to be properly earthed). If you have your own socket board with FI switch and the socket board is wired correctly, your FI switch will engage in such cases. However, it does not help against an earth line wired for electrocution, so it does not save you the screw driver check before plugging in your socket board.