<?php foreach ($linky as $ln): ?>
<tr>
<td><?php echo $ln['id']; ?></td>
<td><?php echo $ln['mag']; ?></td>
<td><?php echo $ln['link']; ?></td>
<td>
<form action="" method="post">
<input type="text" name="linkk" >
<input type="submit" value="Сохранить">
</form>
</tr>
<?php endforeach ?>
if (isset($_POST['linkk'])) {
$link = htmlentities(mysqli_real_escape_string($connection, $_POST['linkk']));
$nlink ="UPDATE linky SET link='$link' where id=" . $ln['id']."";
$result = mysqli_query($connection, $nlink) or die("Ошибка " . mysqli_error($connection));
}
<?php foreach ($linky as $ln): ?>
<tr>
<td><?php echo $ln['id']; ?></td>
<td><?php echo $ln['mag']; ?></td>
<td><?php echo $ln['link']; ?></td>
<td>
<form action="" method="post">
<input type="text" name="linkk" >
<input type="hidden" name="id" value="<?php echo $ln['id']; ?>" >
<input type="submit" value="Сохранить">
</form>
</tr>
<?php endforeach ?>
if (isset($_POST['linkk'])) {
$link = htmlentities(mysqli_real_escape_string($connection, $_POST['linkk']));
$nlink ="UPDATE linky SET link='$link' where id=" . $_POST['id']."";
$result = mysqli_query($connection, $nlink) or die("Ошибка " . mysqli_error($connection));
}