Having a little trouble working out the problem. Is it that you're playing a ranged champ, and you try to right-click the enemies to attack from a distance and end up running toward them instead?
If that's the case, then you just need to practice being more precise. That's the problem I had when trying ranged after a long run of melee games. Kept jumping right into the middle of a fight by accident and getting blown up, haha. Also remember that you can just right-click back toward your turret to run away from a misclick.
Finally, if you ever want your champ to stand in place without moving or attacking, you can either press the s key or press and hold the h key.