Ah, that's what I was afraid of.
What you're doing, then, is vulnerable to a race condition since the next ID value could change between the time you retrieve it and the time you actually use it. I don't know what your specific application is, but a better method would be to simply insert the new data and retrieve the ID value it was assigned (not by doing a SELECT query).