Php 从表中删除-通过表单

Php 从表中删除-通过表单,php,sql,indexing,sql-delete,Php,Sql,Indexing,Sql Delete,我有一个HTML表格,它显示了我的所有表格条目。表中每个SQL条目旁边都有一个删除按钮 我希望能够删除用户选择的条目。我制作了发布PHP_Self的表单,并将while循环中的索引$I作为引用传入: $i = 0; while($row = mysqli_fetch_array($result)){ ?> <tr> <td> <? echo $row['uniqueIdentifier']; ?&g

我有一个HTML表格,它显示了我的所有表格条目。表中每个SQL条目旁边都有一个删除按钮

我希望能够删除用户选择的条目。我制作了发布PHP_Self的表单,并将while循环中的索引$I作为引用传入:

$i = 0;

while($row = mysqli_fetch_array($result)){

    ?>

    <tr>
        <td>
            <? echo $row['uniqueIdentifier']; ?>
        </td>

        <td>
            <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
                <input type='hidden' name='remove_entrie_ID' value='<? echo $i; ?>' />
                <input type='submit' value='Delete' name='remove_entrie'>
            </form>
        </td>

    </tr>

    <?

    $i++;

}
我基本上是使用$I来选择表是如何加载的索引,然后使用它来选择要删除的行。但我觉得这是不可能的


我基本上想删除用户从表中选择的一行。

您不需要$I变量。只需在列表中进行简单修改:

while($row = mysqli_fetch_array($result)){
?>
<tr>
    <td>
        <? echo $row['uniqueIdentifier']; ?>
    </td>

    <td>
        <form action="" method="post">
            <input type="hidden" name="remove_entrie_ID" value="<? echo $row['uniqueIdentifier']; ?>" />
            <input type="submit" value="Delete" name="remove_entrie">
        </form>
    </td>

</tr>

<?
}


最好在post变量中转义特殊字符等,以避免sql注入。

Sidenote:INDEX是一个保留字,可以在其周围使用反勾号,也可以使用另一个名称。另外,请确保打开了“短打开”标记。如果不是的话,就换个坝吧,弗雷德,我只是想发个帖子谢谢你,谢谢你vurry mooch@达贡:那不是我最好的:::埃尔维斯:::模仿,但很接近。我还可以得到我的sea gahr吗?好的,那么删除用户选择的行的最佳方法是什么?我怎样才能引用它?我不能使用“uniqueIdentifier”,因为具有讽刺意味的是,它们在行中是重复的-我不想删除错误的一个-您需要某种方法来唯一地标识行。为什么表中没有一个自动递增的主键呢?正如我前面提到的:我不能使用“uniqueIdentifier”,因为它不是唯一的,它们在表中是一些重复项,我不想删除错误的主键one@OliverJones当然,您必须有一个列,其中没有重复条目?对不起,我没有注意到。您可以尝试以类似的方式将您的id与其他列一起使用。只需从表中添加一些其他字段作为删除条件。每行中只有一个时间戳和一个this uniqueId。我可以添加任何我想添加的内容-我继续添加了另一个名为indexId的内容,我让PHP计算有多少行,然后增加该值。。我不知道这是否有效。。。两个用户同时使用post到PHP,并设法获得相同的计数值,会发生什么情况?那我就完蛋了
while($row = mysqli_fetch_array($result)){
?>
<tr>
    <td>
        <? echo $row['uniqueIdentifier']; ?>
    </td>

    <td>
        <form action="" method="post">
            <input type="hidden" name="remove_entrie_ID" value="<? echo $row['uniqueIdentifier']; ?>" />
            <input type="submit" value="Delete" name="remove_entrie">
        </form>
    </td>

</tr>

<?