Update in the database via javascript

Asked

Viewed 1,084 times

-2

I need to make a button that when the user clicks on the corresponding row he will execute the following code without refresh:

Line Code:

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

Row:

<?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 it should be an onclick function in javascript but I do not know how to develop it to change in javascript

  • A little about front-end and back-end http://answall.com/a/177050/3635

1 answer

5


Javascript is a client-side working language (browser). Therefore, it has no direct connection to a Mysql server.

Also, if you had, it would be a problem, since you would need to specify a password for connection to the bank.

And so, anyone who reads your Javascript file could see your password. That would be a problem, it’s not even?

So, use a server-side acting language, like PHP for example, to connect to Mysql and do some database operation.

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

Maybe you’re confusing the concepts a little bit. That’s why it’s important to make this clear.

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

See some examples:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.