This is Dr. David
you should ice your knee to decrease inflammation
and you need to see your primary doctor as soon as possible
and ask for an MRI scan of your knee.
you could have torn a meniscus or torn a ligament in your knee.
you can try to move your knee in short ranges to keep mobility in your knee.
What can I do to stop it happening again before I get to see knee Dr?
you really need to not lock your knees.
you most likely will need to use crutches to take weight off of your knee to make sure it doesn't happen again.
you might need to use an ace elastic bandage around your knee to give support to the knee.
or use an elastic knee brace on your knee.