Is it ok to take anti inflammatory drugs when you have stomach ulcers?

NO. These drugs are one of the prime causes, however, there are some products with stomach protective ingredients, so speaking to you doctor may help you chose the least dangerous route.