I played two hands in a row (0.25/0.50 nl) and lost both hands because the other players had a flush. I think I made the right bet. I am a beginner, so I want to ask you if I played the hands correctly and just got unlucky.

First hand I flopped two eights and had one eight in hand so I flopped trips eigths. I saw the danger of the flush draw because the flop also confronted me with two clubs. So if someone had two clubs as hole cards I have to make a bet that will give him bad odds to call.

The pot was $5 and I made a pot sized bet ($5). So if the other player had a flush draw the call would be unjustified: he has to pay 100% of the pot while he has only has a 37 % chance of getting the flush. But he made the call (jack ten of clubs with no jack or ten on the flop and no straight chances for him), got the flush and took my money.

The second hand I got dealt AK, I raised pre-flop 4*BB. One person calls. Two of the three cards on the flop are hearts including the ace of hearts. Again I am faced with the the same situation, a possible flush draw. The pot is about $5 dollars and I make a $6 bet. Again I get called, the turn shows Kh and again I am beat by the flush.(the player had jth, no pair, no straight chances end played for the flush only)

After this I immediately left the table and stopped playing.

Did I play this hands correctly or did I do something wrong?