codice HTML:
...
<td><input type="text" value="<?php echo $Cart03; ?>" id="<?php echo $Cart06; ?>"></td>
<td><input type="text" value="<?php echo $Cart04; ?>" id="<?php echo $Cart06; ?>"></td>
<td><button onclick="aggiornaDato(<?php echo $Cart06; ?>, <?php echo $Cart03; ?>, <?php echo $Cart04; ?>)">Aggiorna!</button></td>
...
<script>
function aggiornaDato(id, tess, cart) {
fetch('update_Cartellino.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `id=${id}&tess=${tess}&cart=${cart}`
})
.then(response => response.text())
.then(data => {
if(data === "success") {
document.getElementById(id).innerText = nTess;
alert("Dato aggiornato con successo!");
}
});
}
</script>
...
e
Codice PHP:
<?php
if(isset($_POST['id'], $_POST['tess'], $_POST['cart'])) {
$id = $_POST['id'];
$tess = $_POST['tess'];
$cart = $_POST['cart'];
$stmt = $cndb->prepare("UPDATE `tabella` SET `Ntessera` = ?, `Cartellino` = ? WHERE `ID` = '" . $id . "'");
$stmt->bind_param('i', $tess, $cart);
if ($stmt->execute()) { echo "success";
} else { echo "error";
}$stmt->close();
}
} else {
echo 'non atteso';
}
?>