To do so there are many ways, but seeing that you do not master the AJAX theme and not complicate it we will do everything in separate files. It's not the most efficient way.I will also leave you an example with a controller, which in this case would be the best way.We started with the simplest version(with separate files)For this case you need 3 files.1o An index.html, the one in charge of displaying the buttons face to the user.2nd A php, active.php, that will activate the content.3o A php, deactivates.php, which will deactivate the content.index.html<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SO</title>
<!-- JQUERY -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<button onclick="funcionActivar()">Activar!</button>
<button onclick="funcionDesactivar()">Desactivar!</button>
</body>
</html>
<script>
function funcionActivar(){
$.ajax({
url: 'activa.php',
success: function (response) {
alert(response);
}
});
}
function funcionDeasactivar(){
$.ajax({
url: 'desactiva.php',
success: function (response) {
alert(response);
}
});
}
</script>
active.php<?php
//Establecemos conexion, ya sea con PDO o como lo hagas tu.
$link = new mysqli("192.168.1.1", "srsole", "my_pass", "module_cli");
$link->set_charset("utf8") or die();
$consulta = "UPDATE usuario SET Trabajo='Activada' WHERE Correo='" . $mail ."';"; //Desconozco de donde sacas $mail, asi que lo pongo tal cual.
$result = mysqli_query($link, $consulta);
echo "Activado con exito!";
?>
deactivate.php<?php
//Establecemos conexion, ya sea con PDO o como lo hagas tu.
$link = new mysqli("192.168.1.1", "srsole", "my_pass", "module_cli");
$link->set_charset("utf8") or die();
$consulta = "UPDATE usuario SET Trabajo='Desactivada' WHERE Correo='" . $mail ."';"; //Desconozco de donde sacas $mail, asi que lo pongo tal cual.
$result = mysqli_query($link, $consulta);
echo "Desactivado con exito!";
?>
Version with counterIn this case we only need 2 files:1o index.html, the one in charge of displaying the buttons face to the user.2o controller.php, to activate/deactivate the content according to the parameter sent (POST).index.html<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SO</title>
<!-- JQUERY -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<button onclick="toggleActivar(1)">Activar!</button>
<button onclick="toggleActivar(0)">Desactivar!</button>
</body>
</html>
<script>
function toggleActivar(x){
$.ajax({
url: 'controller.php',
data: {"activo": x},
type: "POST",
success: function (response) {
alert(response);
}
});
}
</script>
controller.php<?php
//Recibimos los datos por POST
$activo = $_POST["activo"]; //esto valdra 1 ó 0
//Establecemos conexion, ya sea con PDO o como lo hagas tu.
$link = new mysqli("192.168.1.1", "srsole", "my_pass", "module_cli");
$link->set_charset("utf8") or die();
if(intval($activo) == 1){
$consulta = "UPDATE usuario SET Trabajo='Activada' WHERE Correo='" . $mail ."';"; //Desconozco de donde sacas $mail, asi que lo pongo tal cual.
$x = "Activado con exito";
}else{
$consulta = "UPDATE usuario SET Trabajo='Desactivada' WHERE Correo='" . $mail ."';"; //Desconozco de donde sacas $mail, asi que lo pongo tal cual.
$x = "Desactivado con exito";
}
$result = mysqli_query($link, $consulta);
echo $x;
?>
It's not exactly a controller, but it's more efficient.