Update by clicking on the button

1

Again, sorry for the inconvenience, but I need to finish this job, and this would be the last thing.

What I need is that, when you click on the update button, this sql statement is executed so that the total of the table is updated:

  

UPDATE invoice1 SET total = (priceUnit * amount);

Is there any way to do it?

I leave the php code in case you want to see something:

Thanks again.

pd: I add photo of the query.php file

    
asked by David Bucci 05.12.2018 в 04:46
source

1 answer

0

You can make an ajax query (I've done it with JQuery, which is easier for me).

Explanation: PHP is only back-end and not front-end, so you could not run a front-end call directly from PHP. (Simple explanation: Front-end = user, back-end = server). So in the middle there is ajax that can execute an external query from the same page. You generate a file .php we will call consulta.php and the button say that you have a id of btnactualizar (since you do not show the html).

$(document).ready(function(){
     $("#btnactualizar").click(function(){
           var url="consulta.php"
           jQuery.ajax({
                url: url,
                type: 'POST',
                success:function(output){
                    //Luego de ejecutar la llamada el output es lo que retornas
                    //con un echo normal
                }
            });
     });
});
    
answered by 05.12.2018 в 05:07