我不知道我的更新代码出了什么问题

I cant figure out whats wrong on my update code

这是我用来显示数据的代码。(registos.php)

<?php
$con = mysqli_connect('localhost','root','');
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}

mysqli_select_db($con,'databaseteste');

$result =mysqli_query($con,("SELECT * FROM `formando2`"));
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}

echo "<table class=mainmenu border='1' width=100% >
<p><caption><h1>Registos</h1></caption></p>
<tr>
<th>Primeiro Nome</th>
<th>Ultimo Nome</th>
<th>Numero C.C</th>
<th>Numero contribuinte</th>
<th>Email</th>
<th>Morada</th>
<th>Código postal</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr><form action=update.php method=post>";
echo "<td><input type=text name=pname value='".$row['PrimeiroNome']."'></td>";
echo "<td><input type=text name=sname value='".$row['UltimoNome']."'></td>";
echo "<td><input type=text name=bi value='".$row['NumeroBI']."'></td>";
echo "<td><input type=text name=contri value='".$row['NumeroContribuinte']."'></td>";
echo "<td><input type=text name=email value='".$row['Email']."'></td>";
echo "<td><input type=text name=morada value='".$row['Morada']."'></td>";
echo "<td><input type=text name=cpostal value='".$row['CodigoPostal']."'></td>";
echo "<td><input type=hidden name=id value='".$row['idformando2']."'></td>";
echo "<td><input type=submit></td>";
echo "</tr>";
}
echo "</table>";
?>

我猜这是在更新代码中给我带来问题的代码。(update.php)

<?php
$con = mysqli_connect('localhost','root','');
if (!$con){die('Could not connect: ' . mysqli_error());}

mysqli_select_db($con,'databaseteste');

$update ="update `formando2` 
                set PrimeiroNome='$_POST[pname]',
                    UltimoNome='$_POST[sname]',
                    NumeroBI='$_POST[bi]',
                    NumeroContribuinte='$_POST[contri]',
                    Email='$_POST[email]',
                    Morada='$_POST[morada]',
                    CodigoPostal='$_POST[cpostal]' 
            where idformando2='$_POST[id]'";

if(mysqli_query($con,$update)){
    header("refresh:1; url=registos.php");}
else{
    printf("Error: %s\n", mysqli_error($con));
}   
?>

当我提交它时,将我重定向到 update.php 页面,然后再次重定向到 registos.php,但数据仍然相同。
Registo Screen

Post update

我想你没有把输入框的名称用单引号或者所有字段的双引号括起来

应该是

回声“”;

您没有关闭表单标签。

你需要

echo "</form></tr>";

而不是

echo "</tr>";

在registos.php

由于此循环显然可以在页面上呈现多个表单,您可能遇到嵌套表单问题,或者只是无效 HTML,导致您 post 返回时出现混淆。