Why pressing the button removes the first entry and not the button I pressed?

Hi all, planned to make work with text(with reviews), but there's the problem - when you click the button, it deletes the first record, not the button which I clicked. Tell me what is my mistake please)
<?
include("db.php");
$query=mysql_query("select * from `otzivi1`");
while($a = mysql_fetch_assoc($query)){
 echo "<center-->
".$a['id']."
 <h2>username:</h2>".$a['name']."
 <h2>user Email:</h2>".$a['email']."
<h2>Ratings:</h2>".$a['stars']."
<h2>Feedback:</h2>".$a['comment']."
";
 echo "
<form action method="post">
<input type="submit" name="access" value="Publish">
<input type="submit" name="spam" value="This is spam!">
</form>
";

if($_POST['access']){
 mysql_query("insert into `otzivi2`(`name`, `email`, `stars`, `comment`) values('".$a['name']."', '".$a['email']."', ".$a['stars'].", '".$a['comment']."')");
 mysql_query("delete from `otzivi1` where `id`= ".$a['id']);
 echo "<span style="color: darkgreen;">Review is published! After 5 seconds the page will restart!</span>";
$_POST['access']=false;
 echo "<meta http-equiv="Refresh" content="5; URL=http://testik.ru/index2.php">";
 } 
if($_POST['spam']){
 mysql_query("delete from `otzivi1` where `id`=".$a['id']);
 echo "<span style="color: darkred;">Review deleted! After 5 seconds the page will restart!</span>";
$_POST['spam']=false;
 echo "<meta http-equiv="Refresh" content="5; URL=http://testik.ru/index2.php">";
}
 echo "";
 echo $a['id'];
}

?>
July 8th 19 at 16:01
1 answer
July 8th 19 at 16:03
Solution
in the form parameters pass id of the record you want to delete, as in $a after the loop lies id of the last record that was processed cycle

in General, I recommend to bring a conclusion separately, logic separately and the code to read better and errors easier to find
Thank you for the tip) - Davon commented on July 8th 19 at 16:06

Find more questions by tags PHPMySQL