Update in the bank via javascript

-2

I need to make a button that when the user clicks the corresponding line it executes the following code without refresh:

Line Code:

mysql_query('UPDATE tbl_publicacao SET status = S WHERE cod_publicacao = $cod_publicacao');"

Line:

<?php $cod_publicacao = $back_query['cod_publicacao'];
$arquivo = $back_query['arquivo']; 
 echo"<a href='upload/publicacoes/{$razao_social}/{$tipo}/{$titulo}/{$ano}/{$arquivo}'>
<i class='ace-icon fa fa-eye bigger-110 hidden-480'></i>&nbsp;Visualizar Arquivo</a>";
?>

I believe that there should be an onclick function in javascript but I do not know how to develop it to change in javascript

    
asked by anonymous 27.02.2017 / 20:57

1 answer

4

Javascript is a language that works on the client side (browser). Therefore, it has no direct connection to a Mysql server.

Furthermore, if it did, it would be a problem, since you would need to specify a password to connect to the bank.

And so, anyone reading your Javascript file could see your password. That would be a problem, would not it?

So, use a server-side language, such as PHP for example, to connect to Mysql and do some operation on the database.

What can be done is to use an Ajax request, which will be sent to the Server, and the Server will execute Mysql and delete the file.

Maybe you're confusing concepts a bit. So it's important to make that clear.

As stated earlier, you can use an Ajax request for this.

Here are some examples:

28.02.2017 / 01:14