There are many reasons why your knee may be giving way and beginning to feel painful, that is why a thorough history should be taken in order to get an idea if it is more of an acute injury or an injury of insidious onset. If for example you were playing soccer and twisted your knee during the game, you may have strained particular ligaments around the knee (MCL, LCL, ACL, and PCL) which are responsible for maintaining stability around the knee joint.
If your knee instability and pain has come on gradually over time, it may be that you have patellar femoral pain syndrome which can be caused by many different factors (lower limb alignment, muscle imbalances, hip instability/weakness). Therefore, it is important to see a physiotherapist about the problem so they can do a thoroughly assessment and find out the main cause of the problem. They then will be able to give you self management techniques and specific exercises to address your knee instability and pain.