The fact that the pain only occurs with swallowing suggest that you probably have some irritation or inflammation in your esophagus, which is the tube that connects your mouth to your stomach. Everything you swallow has to pass down your esophagus and, therefore, if it is irritated, the very act of swallowing can cause pain.
There are several different causes of inflammation of the esophagus, or esophagitis, which might be causing your pain.
One of these is simple bad heartburn or acid reflux
. When acid leaves the stomach and enters the esophagus, it causes a chemical burn which might be cause your symptoms.
Another very common problem is something called pill esophagitis, where medications that you take may directly irritate the esophagus. By far the most common medications which cause this are the bisphosphonates, which are taken to protect bone density, but many other more common medications can do this as well.
Finally, certain infections of the esophagus, from viruses and fungi, can cause esophagitis.
I would suggest that you start by making an appointment with your primary care doctor
to evaluate this problem, especially if the symptoms persist. They can help you decide what to do to relieve the symptoms.