'How do I decrease the quantity of an item while uploading the update quantity into the database and showing it on the UI at the same time?

Ive been asked to create an inventory page where it should display detailed item information like id, name, image, description, price, quantity, supplier name, sold, etc. This page should have a Button named delivered. Once this button is clicked, it will reduce the quantity of the item by one. And i will also have to make sure that this data is saved on the database, and the change in quantity is displayed on the website. The problems that I'm facing

  1. I have to click on the button twice to update it on the database
  2. I have to reload the page to show the updated quantity on the UI


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source