Possessing drugs can get you into a lot of trouble with the law, but you have rights that you can exercise to make sure you're treated fairly. To obtain a conviction against you, a prosecutor has to prove that you knew that you were in possession of drugs and were in possession of those drugs illegally. You must have had control over the substances as well.
How can you defend yourself against a drug charge for a prescription medication?
You must have a valid prescription for some kinds of drugs that would otherwise be illegal to possess; if you can present one, then the prosecution will be unable to move ahead with a case in most situations.
Having a prescription is just one kind of potential defense to a drug crime. Lacking knowledge that you were in possession of a controlled substance is another. For example, if you drove a friend home and that friend had drugs that were left behind in the vehicle, you may not have known about them. If the drug wasn't intended for human consumption, that may also be a good defense. This is a strong defense for scientists and those who study illicit drugs, since they may be found with these materials outside the lab.
If you are carrying medical marijuana, you must have a prescription and medical marijuana card. You should only be in possession of the legally allowed amount of marijuana, and you should not be using a vehicle while intoxicated. If you are not intoxicated and have those two documents, then you should not be charged with a drug crime.
Source: FindLaw, "Texas Drug Possession Laws," accessed Sep. 20, 2016