If your Playstation 3 controller is "going crazy" with random inputs then their is probably a very simple fix. (unless if it's water damage :( )
The most common issue with the PS3 DualShock 3 PS3 controller is the little sponge deteriorating over time. This sponge pushes the connector to the circuit board, I don't know why Sony didn't go for a default ribbon connector w/ a clip. Especially because this "solution" connects the majority of the buttons to the PCB.
I always do a simple repair to fix this issue: strengthen the connection. To do that we first have to disassemble the controller. Open the controller by removing the 4 screws on the back, we are lucky that none are hidden underneath a "warranty sticker". Disconnect the battery to make sure not to damage anything, (this might not be possible depending on the model). Then remove the screw that holds the circuit board in place, fold it up and you will see the connector I'm talking about.
Gently pull the ribbon cable up and remove the little sponge underneath. You can replace the sponge with a thicker alternative, but I however make the original one thicker. I do this by adding a couple of layers of electrical tape to the underside of the sponge:
Try not to make it too thick as you'll be flexing the PCB too much. But you will have to make it thick enough that the connection is reliable
Then place the modified sponge underneath the ribbon and assemble the controller
At last, everything should be working correctly & reliably again! While you are at it make sure to give it a good clean after all these years of playing games ;).