jQuery script isn’t posting to database

You use globals 🙁 whenever you think that you need to use a global you should automatically stop coding and invest as much time as it takes to remove that need.

In your case it seems like you assume that global variables persist between Ajax request, but they don’t. In addition your design of the code is broken as in client server configuration you can not assume that the server state remain the same between request, therefor when you need to do some operation you need to do it in one request and not to split it into 3. It is good design to let the user know that he can not perform an operation, but you need to actually recheck all conditions when getting to actually performing the operation even if you checked them when you displayed the UI to the user.