While MRI and X-ray are both imaging techniques for organs of the body, the difference is that MRI images provide a 3D representation of organs, which X-Rays usually cannot.
X-Rays are beams of high frequency (has a wavelength between 10 and 0.1 nanometers) of the electromagnetic spectrum that can easily pass through low density (atomic number) material but not through materials that have high density. Therefore, solid objects like kidney stones and bones come out very clear in the X-Ray image.
MRI makes use of an oscillating magnetic field that is perpendicular to an extremely strong principle magnetic field along which the organ that needs to be scanned is placed. This oscillating field makes the hydrogen atoms within the organ to get magnetized in a direction that is perpendicular to the principle magnetic field.
X-Ray technology is used to employ radiography and other techniques for diagnostic imaging. X-Rays are useful to detect pathology of the skeletal system and to detect certain diseases in the soft tissue. For e.g. identification of pneumonia, pulmonary edema, lung cancer or abdominal X-ray are all effective. They are helpful in detecting gallstones or kidney stones.
MRIs are used for distinguishing pathologic tissue from the normal tissue. Unlike traditional X-Rays that use ionizing radiation, MRIs use non-iodizing radiation. MRIs offer excellent image clarity and different types of MRIs scans enable taking different images with a great clarity.
edit Hazards posed
The most important problem with X-Rays is the danger they pose due to prolonged exposure. The radiation can cause damage to the soft tissues. X-Rays use radiation in order to get an internal view of the body and hence many X-Rays cannot be taken at a single time. The rays are so powerful that they can knock electrons off of the atoms when they hit them. The result is the production of ions that create many abnormal reactions in the body. X-Rays have the ability to alter DNA as well. But with the MRI several cross sectional images can be taken at the same time without creating any biological hazards.
Other than radiation and its associated risks (especially for infants), there are few limitations for X-rays. It is a mature and well-established procedure.
MRIs on the other hand, can be disadvantageous for people who are claustrophobic. An examination can last up to 90 minutes, which some people may find difficult to handle. Patients with pacemakers or other metal objects can also not be examined MRI. Finally, MRI is considerably more expensive than an X-ray.