Any change to a MySQL database must happen on the server-side. However, since you are also initiating the change from the client-side and displaying data, you will need to use AJAX to implement that.

Take a look at W3Schools AJAX Tutorial to get you started.