You're over-writing your texture bindings; this is a side-effect of OpenGL's bind-to-modify behaviour and happens because in non-DSA OpenGL state used for drawing is the same as state used for creating/modifying objects.
At line 180 you have the following:
glBindTexture(GL_TEXTURE_2D,6)
Then at line 249 you have the following:
glBindTexture(GL_TEXTURE_2D,0)
These calls will over-write the binding for GL_TEXTURE3 and when you come to draw texture '0' (which is actually a valid texture object in OpenGL) will be bound to it.
If you hadn't been un-binding (which IMO is a bad practice) you would have probably caught this sooner because you would have clearly seen the wrong texture being used.
To resolve, either re-bind '6' to GL_TEXTURE3 before drawing; or reserve a texture unit for updates and make that active before doing any updates; or use direct state access. I personally recommend a combination of direct state access (assuming your target market will stand it) and bind-before-use, getting rid of all unbinding.