<form method="post" action="" name="save">
<input type="text" name="del" value="">
<input type="hidden" name="id" value="<?=$test['id']?>">
<input type="text" name="summa" value="">
<input type="text" name="logic" value="">
<button type="submit" name="save">Save</button>
</form>
$(function () {
$('.save').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "test.php",
data: $(this).closest('form').serialize(),
success: function() {
alert("Данные сохранены");
}
});
});
});
if(isset($_POST['save']))
{
$link->set_charset("utf8");
$id = (int)$_POST['id'];
$summa = (int)$_POST['summa'];
$del = (int)$_POST['del'];
$log = strip_tags(trim($_POST['logic']));
$mysql = "UPDATE Users SET logic='$log', sum='$summa', del='$del' WHERE id=$id";
$result = mysqli_query($link, $mysql);
<input type="text" id="del" name="del" value="">
<input type="hidden" id="id" name="id" value="<?=$test['id']?>">
<input type="text" id="summa" name="summa" value="">
<input type="text" id="logic" name="logic" value="">
<button id="save" name="save">Save</button>
$("#save").click(function(){
$.ajax({
type: "POST",
'dataType': 'json',
url: "test.php",
data: {
id: $('#id').val(),
summa: $('#summa').val(),
del: $('#del').val(),
logic: $('#logic').val(),
},
success: function(data) {
if(data['status'] == 'success'){
alert('Данные переданы');
}
else{
alert('Произошла ошибка!');
}
}
});
});
$link->set_charset("utf8");
$id = (int)$_POST['id'];
$summa = (int)$_POST['summa'];
$del = (int)$_POST['del'];
$log = strip_tags(trim($_POST['logic']));
$mysql = "UPDATE Users SET logic='$log', sum='$summa', del='$del' WHERE id=$id";
if(!mysqli_query($link, $mysql)){
$status = 'error';
}
else{
$status = 'success';
}
echo json_encode(['status' => $status]);