How to get name attribute of an image from php when click on it

I want to get the name attribute of an imagen when someone click on it.
Then, with the name, I will access a MySQL database with this name as a searching parameter for the query.
But I am not able to get the name of an image from php.

Can someone help me?

This is the code that I have, I suppose to have a php function in the onclick attr.

<a class="img_a" onclick="" name="xxx">   
    <figure class="img_figure">
        <img class="img_user" src="users/xxx.png" alt="">
    </figure>
</a>

<a class="img_a" onclick="" name="yyy">   
    <figure class="img_figure">
        <img class="img_user" src="users/yyy.png" alt="">
    </figure>
</a>


Source: stackoverflow-php

PHP ajax image upload multiplies

Spent whole night with this script
but cant fix the bug.
it would be better if anyone can help me on this

say if i select an image and click upload it uploads current image file
then if i select another image and click upload it upload 2 new files u=in directory and it increase every time

here is my sourcecode


Source: stackoverflow-php