1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| <?php
$conn = mysqli_connect("localhost", "root", "", "db");
// Choose a function depends on value of $_POST["action"]
if($_POST["action"] == "insert"){
insert();
}
// Function
function insert(){
global $conn;
$desktops = $_POST['desktops'];
$laptops = $_POST['laptops'];
$dockings = $_POST['dockings'];
$screens = $_POST['screens'];
$printers = $_POST['printers'];
$keyboards = $_POST['keyboards'];
$mice = $_POST['mice'];
$query_update = 'UPDATE t_utilisateurs SET Desktops = "'.$desktops.'", Laptops = "'.$laptops.'", Dockings = "'.$dockings.'", Screens = "'.$screens.'", Printers = "'.$printers.'", Keyboards = "'.$keyboards.'", Mice = "'.$mice.'" WHERE ID ="'.$_SESSION['ID'].'"';
mysqli_query($conn, $query);
}
?>
<form id="myForm" action="" method="post" autocomplete="off"><!--Ajax-->
<li><input id="desktops" name="desktops" type="number" value="<?php echo $desktops; ?>" size="5" maxlength="5" /> Desktops</li>
<li><input id="laptops" name="laptops" type="number" value="<?php echo $laptops; ?>" size="5" maxlength="5" /> Laptops</li>
<li><input id="dockings" name="dockings" type="number" value="<?php echo $dockings; ?>" size="5" maxlength="5" /> Dockings</li>
<li><input id="screens" name="screens" type="number" value="<?php echo $screens; ?>" size="5" maxlength="5" /> Écrans</li>
<li><input id="printers" name="printers" type="number" value="<?php echo $printers; ?>" size="5" maxlength="5" /> Imprimantes</li>
<li><input id="keyboards" name="keyboards" type="number" value="<?php echo $keyboards; ?>" size="5" maxlength="5" /> Claviers</li>
<li><input id="mice" name="mice" type="number" value="<?php echo $mice; ?>" size="8" maxlength="5" /> Souris</li>
<button type="submit" name="button" onclick = "insert();">Submit</button>
<input type="submit" name="submit_form" value="Mettre à jour" />
</form>
<!-- Insertion Ajax -->
<script type="text/javascript">
// Prevent form from submit or refresh
var form = document.getElementById("myForm");
function handleForm(event) { event.preventDefault(); }
form.addEventListener('submit', handleForm);
// Function
function insert(){
$(document).ready(function(){
$.ajax({
// Action
url: 'updateParcIT.php',
// Method
type: 'POST',
data: {
// Get value
desktops: $("input[name=desktops]").val(),
laptops: $("input[name=laptops]").val(),
dockings: $("input[name=dockings]").val(),
screens: $("input[name=screens]").val(),
printers: $("input[name=printers]").val(),
keyboards: $("input[name=keyboards]").val(),
mice: $("input[name=mice]").val(),
action: "insert"
},
success:function(response){
// Response is the output of action file
if(response == 1){
alert("Données ajutées avec succès!");
}
else{
}
}
});
});
}
</script> |
Partager