If you want to run some PHP code while clicking the button and don’t want to refresh it, then you can send ajax request to your server using javascript. You can also update your page dynamically using the same.
solved Set PHP varibles on button press without using POST or GET