Execution request on button
Execution request on button
vinkey33
Posts: 7Questions: 4Answers: 0
Hello, I have a small problem of requete mysql I explain I would like to put one day the column "status" via a checkbox by clicking a plus button, then I click the button nothing happens.
I would like to know if my code is good
Requette.php
<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "Mm101010";
$dbname = "smartphone";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
/* Database connection end */
$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");
}
}
<?php
>
```
?>
index.php
```html
<!DOCTYPE html>
<html>
<title>Smartphone</title>
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="css/bouton.css">
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" >
$(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
});
}
});
} );
</script>
<style>
div.container {
margin: 0 auto;
max-width:760px;
}
div.header {
margin: 100px auto;
line-height:30px;
max-width:760px;
}
body {
background: #f7f7f7;
color: #333;
font: 90%/1.45em "Helvetica Neue",HelveticaNeue,Verdana,Arial,Helvetica,sans-serif;
} </style>
</head>
<body>
<h2 align="center">Affectation</h2><br/><br/><br/>
<center>
<button href="Abonnement.php" id="update_affect" class="bouton_dans_page">Abonnement</button>
<a href="Employe.php" class="bouton_dans_page"> Employe</a>
<a href="Equipement.php" class="bouton_dans_page"> Equipement</a>
<a href="Modele.php" class="bouton_dans_page"> Modele</a>
<a href="Nouvelle_Affectation.php" class="bouton_dans_page"> Nouvelle Affectation</a>
<a href="Employe.php" class="bouton_dans_page"> Employe</a>
<a href="Menu_Smartphone.html" class="bouton_dans_page"> Menu Smarphone</a>
<table id="vu_affect_empl" cellpadding="0" cellspacing="0" border="0" class="display" width="100%"><br/><br/><br/><br/>
<thead>
<tr>
<th><input type="checkbox" id='action_ligne' /></th>
<th>USER ID</th>
<th>Nom</th>
<th>Prenom</th>
<th>Num SIM</th>
<th>PIN Terminal</th>
<th>PIN SIM</th>
<th>Num EMEI</th>
<th>Date Debut</th>
<th>Date Fin</th>
<th>Vitre</th>
<th>Coque</th>
<th>Support Vehicule</th>
<th>Actif</th>
<th>Statut</th>
</tr>
</thead>
</table><br><br>
<button type="button" class="Menu" id="update_affect" name="Supprimer_affect">Suprimer Affectation</button>
<button class="Menu" type="button" id="C_R_E" onclick="javascript:Confirmer" name="C_R_E">Confirmer Retour Equipement</button>
<a href="Equipement_Modal.php" class="Menu" id="R_E" name="R_E"> Remplacer Equipement</a>
<button class="Menu" type="button" id="A_S_L" name="A_S_L">Ajout et Supression Ligne</button>
<button class="Menu" type="button" id="C_R_A" name="C_R_A">Confirmer Retour Abonnement</button>
<button class="Menu" type="button" id="Reaff_Equip" name="Reaff_Equip">Reaffectation Equipement</button>
</center>
</body>
</html>
thank you
edited by allan Syntax highlighting
This discussion has been closed.
Answers
Does the Ajax request get sent? This is more of a generic Javascript question rather than DataTables specific by the looks of it. It might be worth asking on StackOverflow.
Allan