A song is in a certain key. There is a scale of that key. If the key is C major, the scale is C, D, E, F, G, A, B, C. We can form chords from those notes. The most common ones are triads - the ones fingered 1, 3, 5.
That's C major - C, E, G.
D minor - D, F, A.
E minor - E, G, B etc.
For 'in-between' notes stick to the notes of the basic scale.
But be warned. Those 'rules' might help you to string together notes that don't sound WRONG. But you'll find an awful lot of songs that go beyond that basic framework. Just about all of them in fact!
For a start, as 'rules' they tell you the blues is wrong. Chromatic chords are wrong. (Songs in C major frequently use C7, F7, F minor, B♭ major chords and many more, without ever departing from a C major framework.)
So don't treat them as rules. Just as a description of the most basic framework of a musical key.
PLEASE don't try to work outward from 'theory'. Look at real music and ask 'what's happening here?' If it breaks a 'rule' - well, we're not in black-and-white any more. We've left Kansas, the 'Summer Holiday' bus is on the road. Glorious Technicolor! And remember the vast majority of movies ARE in colour. Film students might sometimes choose to work in monochrome as an exercise, but they aren't expected to do so for years before graduating to colour. (Actually, this analogy is going a bit wrong, maybe they should...)