Table with data from the database:

<tr> <td><div class="alert <?=$colorClass?>" role="alert"><p><?=$users['id']?></div></td> <input type="hidden" name="form_id" value="<?=$users['id']?>"> <td><div class="alert <?=$colorClass?>" role="alert"><p><?=htmlspecialchars($users['delivery_adress'], ENT_QUOTES)?></p></div></td> <td><div class="alert <?=$colorClass?>" role="alert"><p><?=htmlspecialchars($users['delivery_time'], ENT_QUOTES)?></p></div></td> <td><div class="alert <?=$colorClass?>" role="alert"><p><?=htmlspecialchars($users['surname'], ENT_QUOTES)?> <?=htmlspecialchars($users['name'], ENT_QUOTES)?> <?=htmlspecialchars($users['second_name'], ENT_QUOTES)?></p></div></td> <td><div class="alert <?=$colorClass?>" role="alert"><p><?=htmlspecialchars($users['sum'], ENT_QUOTES)?></p></div></td> <td><button type="button" name="delivery_status" value="1" class="btn btn-xs btn-success mb-3" id="delivered">Отдал</button></td> <td><button type="button" name="delivery_status" value="2" class="btn btn-xs btn-danger mb-3">Отказ</button></td> <td><button type="button" name="delivery_status" value="3" class="btn btn-xs btn-warning mb-3" data-toggle="modal" data-target="#exampleModalLong">Перенос</button></td> </tr> 

dost.php, which handles it:

 <?php require_once('db.php'); if(!empty($_POST['delivery_status'])) { $form_id = (int) $_POST['form_id']; $status = (int) $_POST['delivery_status']; $SQL = "UPDATE Users SET delivery_status='$status' WHERE id='$form_id'"; $result = mysqli_query($link, $SQL); } ?> 

AJAX, which I wrote, and which for some reason does not work, i.e. The data received from the button is not saved in the database, but the blank page with dost.php is simply loaded.

 $('button[name="delivery_status"]').on('click', function() { let $btn = $(this); let id = $btn.closest('tr').find('input[name="form_id"]').val(); // получаем id // формируем данные let data = { form_data: id, delivery_status: $btn.val() }; $.ajax({ type: "POST", url: "dost.php", data: data }).done(function() { alert("Данные сохранены"); }); return false; }); 

I tried file_put_contents ("test.txt", $ _POST ['form_id']); - correct id values ​​are saved there. Wardamp post-request looks like this, i.e. value buttons are not transferred. array (2) {["form_id"] => string (1) "1" ["delivered"] => string (0) ""} There are no errors in the console, php gives 200, only this: [Violation] Forced reflow while executing javascript. The SQL query is correct, i.e. on pure php with reloading the page works out correctly. Help to understand, please. It is necessary that, depending on the button pressed, 1, 2 or 3 are entered in delivery_status, tied to id.

  • try $ _REQUEST ['delivery_status'] - Vfvtnjd
  • @Vfvtnjd and what will it give? - web2k17
  • delivery_status: $ btn.attr ('value') should be when you fill in let data - Vfvtnjd

0