I have this HTML table with data from MySQL database and form for adding/editing rows in this table. If I add new row, everything works fine, but when I want to edit, I dont know how to pre-fill input text fields in this form. I have id of specific row saved as id of each editing button, but I dont know how to get know the ID from this clicked button. And should I have to do it with PHP or JS?
<table class="table table-striped">
<thead>
<tr>
<th> Poradi</th>
<th> Jmeno</th>
<th> Prijmeni</th>
<th> Adresa</th>
<th> Mesto</th>
<th> Telefon</th>
<th> Email</th>
</tr>
</thead>
<tbody>
<?php
$db = new PDO(
"mysql:host=localhost;dbname=xyz",
"xyz",
"xy"
);
$stmp = $db->prepare("SELECT * FROM user");
$stmp->execute();
$data = array();
while ($row = $stmp->fetch()) {
$data[]=($row);
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['login'] . "</td>
<td>" . $row['password'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['surname'] . "</td>
<td>" . $row['address'] . "</td>
<td>" . $row['city'] . "</td>
<td>" . $row['phone'] . "</td>
<td>" . $row['email'] . "</td><td>";
$id = $row['id'];
echo "<a><i class='glyphicon glyphicon-pencil' id=$id></i></a></td>
</tr>";
}
?>
</tbody>
</table>
</div>
<div class="sideMenu">
<form method="post" class="form-group" action="add.php">
<h1>Pridat servis</h1>
<input type="text" name="name" placeholder="Jmeno" required autofocus>
<input type="text" name="surname" placeholder="Prijmeni" required>
<input type="text" name="address" placeholder="Adresa" required>
<input type="text" name="city" placeholder="Mesto" required>
<input type="tel" name="phone" placeholder="Telefon" required>
<input type="email" name="email" placeholder="Email" required>
<div class="btn-toolbar">
<button class="btn" type="submit">Ulozit</button>
<button class="btn" type="button">Zrusit</button>
</div>
</form>
<div class="icon-close">
<img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/uber/close.png">
</div>
</div>