Again, creating the connection in this function and then closing it each time is a bad idea. You should create the connection at the top of the page, use it throughout the page, and then close it at the end of the page.
But that's not your error.
I'm more than curious: You have this error msg
add_to_database = "Unable to add "&jpg_name(0)&" to database! "&Err.Description&"<br />"&sql&"<br /><br />"
Where in the heck is the variable jpg_name
coming from? It's clearly not defined in that function.
But I don't think that's your error.
I guess the first thing I would do is make sure the error isn't coming *FROM* the function.
So *TEMPORARILY* just change the function to this:
add_to_database = true
If the error persists, then you have some problem with code ordering, though I don't see what it is.
If the error goes away, then it must actually be someplace inside that function and is simply not showing until you get back out of it.