Есть таблица с данными, нужно реализовать редактирование записей в модальном окне, как передать данные конкретной записи в модальное окно в инпуты ?
Модальное окно
Как заполнить его данными конкретной записи из таблицы ?
Я пробовал через GET параметр передавать ID записи, потом через него выполнять запрос с условием выбранного ID, если кнопка нажата, затем вставлять полученные данные в модальное окно, но у меня оно закрывается сразу же после открытия.
код таблицы:
<table class="table table-sm table-bordered table-hover" style="font-size: 12px;">
<thead class="table-secondary">
<tr>
<th>№</th>
<th>ПОДРАЗДЕЛЕНИЕ</th>
<th>ТИП ТЕХНИКИ</th>
<th>ПРОИЗВОДИТЕЛЬ</th>
<th>МОДЕЛЬ</th>
<th>СЕРИЙНЫЙ НОМЕР</th>
<th>ИНВЕНТАРНЫЙ НОМЕР</th>
<th>ДАТА ВВОДА В ЭКСПЛУАТАЦИЮ</th>
<th>ДЕЙСТВИЯ</th>
</tr>
</thead>
<tbody class="table-light">
<?php if (!empty ($ressprav)){ foreach ($ressprav as $resspr){ ?>
<tr>
<td style="width: 50px"><?php echo $resspr->id_spravtech; ?></td>
<td><?php echo $resspr->name_subdivision; ?></td>
<td><?php echo $resspr->type; ?></td>
<td><?php echo $resspr->manufacture; ?></td>
<td><?php echo $resspr->model; ?></td>
<td><?php echo $resspr->serial_number; ?></td>
<td><?php echo $resspr->inventary_number; ?></td>
<td><?php echo $resspr->date; ?></td>
<td>
<div class="bttnaction">
<div class="bttnactiongroup">
<a href="?update_id=<?php echo $resspr->id_spravtech; ?>">
<button class="btn btn-secondary btn-sm" data-bs-toggle="modal" data-bs-target="#updatetech">
<i class="fa fa-edit"></i>
</button>
</a>
<a href="#">
<button class="btn btn-danger btn-sm">
<i class="fa fa-trash" ></i>
</button>
</a>
</div>
</div>
</td>
</tr>
<?php
}?>
<?php }else{?>
<tr><td colspan=9>В БАЗЕ ДАННЫХ НЕТ ЗАПИСЕЙ</td></tr>
<?php }?>
</tbody>
</table>
модальное окно:
<div class="modal fade" id="updatetech" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Редактирование техники  </h5><h5 class="modal-title text-danger" id="exampleModalLabel"></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="post">
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Подразделение</span>
<input value="<?php echo $resselecttechupdate[0]->name_subdivision?>" required name="manufacture" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Тип техники</span>
<input value="<?php echo $resselecttechupdate[0]->type?>" required name="manufacture" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Производитель</span>
<input value="<?php echo $resselecttechupdate[0]->manufacture?>" required name="manufacture" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Модель</span>
<input value="<?php echo $resselecttechupdate[0]->model?>" required name="model" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Серийный номер</span>
<input value="<?php echo $resselecttechupdate[0]->serial_number?>" required name="serialnumber" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Инвентарный номер</span>
<input value="<?php echo $resselecttechupdate[0]->inventary_number?>" required name="inventarynumber" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<span class="input-group-text" id="inputGroup-sizing-sm">Дата ввода в эксплуатацию</span>
<input value="<?php echo $resselecttechupdate[0]->date?>" required name="date" type="date" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
<button name="updatetech" type="submit" class="btn btn-primary">Сохранить</button>
</form>
</div>
</div>
</div>
</div>