Is it a PS/2 keyboard? Make sure you're putting it in the right port. If you put the keyboard plug into the mouse port, the keyboard lights will come on and then turn off, just like you said.
Why is the plug loose? Is the plug worn out a bit? Try a different/newer keyboard. Also, try plugging the keyboard in while the computer is off, then turn it on.