I did the right thing but I feel stupid

I have met a personal trainer and we developed a feeling towards each other. He is married and I know the way we chat on social media is not appropriate. I have been involved with a married man before and it caused me depression and mental health issues. I didn’t want to get into the same situation but since I already paid 30 sessions of personal training, I was reluctant to admit I am falling back to the old path.

Today, the trainer confessed to me that he indeed had an affair while being separated from his wife 10 years ago with someone who is significantly younger. When I heard about this, I just knew I had to say no to him for continuing the training relationship. He also confessed to me that he thinks he is being selfish for wanting to stay connected with me and spending time with me.

I know I did the right thing to cut the ties with him and told him I no longer will be training with him. But at the same time, I paid for sessions and completely went head over to heels for him in the beginning, despite of knowing that he was married. I feel bad for myself for not being able to pull myself out of the situation earlier.

Why am I feeling this way? How to deal with this feeling? Did I do the right thing?