Everywhere you use $location['file']['name'] is wrong.
It should just be $location since it holds the file location, with the hash attached.
Also, it cannot be successfully moving the file with $location['file']['tmp_name']
You want $_FILES['file']['tmp_name']
I believe you believe that $location is a copy of your $FILES array with the modified file name. This is incorrect. All of your files data is still in $FILES except the real file location (after you move it) is in $location, since we attached the hash to it.
In regards to the SQL error, change die ("The avatar was not added to the specified user!") to die(mysql_error()) and post up the error please.