Bonjour, j’ai un petit soucis de requete mysql je m’explique j’aimerais mettre a jour la colonne “statut” via un checkbox en cliquant sur un bouton mais lorsque je clique sur le bouton rien se passe.
je voudrais savoir si mon code est bon
requette.php
<?php
$servername = "localhost";
$username = "root";
$password = "Mm101010";
$dbname = "smartphone";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
$data_ids = $_REQUEST['data_ids'];
$data_id_array = explode(",", $data_ids);
if(!empty($data_id_array)) {
foreach($data_id_array as $Or_Affectation) {
$sql = "UPDATE abonnements SET Statut = 'Non Affecté' ";
$sql.=" WHERE Or_Affectation = '".$Or_Affectation."'";
$query=mysqli_query($conn, $sql) or die("supr_Affect.php: Suprimer Affectation");
}
}
?>
AJAX
$(document).ready(function() {
var dataTable = $('#vu_affect_empl').DataTable( {
"processing": true,
"serverSide": true,
"columnDefs": [ {
"targets": 0,
"orderable": false,
"searchable": false
} ],
"ajax":{
url :"Affectation.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".vu_affect_empl-error").html("");
$("#vu_affect_empl").append('<tbody class="vu_affect_empl-error"><tr><th colspan="3"></th></tr></tbody>');
$("#vu_affect_empl_processing").css("display","none");
}
}
} );
$("#action_ligne").on('click',function() { // bulk checked
var status = this.checked;
$(".updateRow").each( function() {
$(this).prop("checked",status);
});
});
$('#update_affect').on("click", function(event){ // triggering delete one by one
if( $('.updateRow:checked').length > 0 ){ // at-least one checkbox checked
var ids = [];
$('.updateRow').each(function(){
if($(this).is(':checked')) {
ids.push($(this).val());
}
});
var ids_string = ids.toString(); // array to string conversion
$.ajax({
type: "POST",
url: "supr_Affect.php",
data: {data_ids:ids_string},
success: function(result) {
dataTable.draw(); // redrawing datatable
},
async:false
});
}
});
} );
bouton
<button class="Menu" id="update_affect">Suprimer Affectation</button>