gpt4 book ai didi

php - 如何通过php中的复选框删除多行

转载 作者:太空宇宙 更新时间:2023-11-03 10:40:36 25 4
gpt4 key购买 nike

我想在按下删除按钮时删除表中选中的多行我的代码是这样的

索引.php

<?php 
if(isset($_POST['Delete']))
{
for($i=0;$i<count($checkbox);$i++){
$ids= $checkbox[$i];
$query2="DELETE FROM products WHERE serialid='$ids'";
mysqli_query($conn,$query2);
}
}
$query2="SELECT * FROM products";
$allresult = mysqli_query($conn,$query2);
?>
<form method="POST" action="index.php">
<input type="button" class="btn btn-danger" name="Delete" value="Delete"/>
</form>
<table class="table table-striped table-hover table-responsive" id="inventoryTable">
<thead>
<tr>
<td>Serial ID</td>
<td>Name</td>
<td>Manufacturer</td>
<td>Keys</td>
<td>Description</td>
<td>Category</td>
<td>Block</td>
<td>Floor</td>
<td>Room</td>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($allresult)) { ?>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row['serialid']; ?>"></td>
<td><?php echo $row['serialid']?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['manufacturer'] ?></td>
<td><?php echo $row['licensekeys'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['categoryname'] ?></td>
<td><?php echo $row['block'] ?></td>
<td><?php echo $row['floor'] ?></td>
<td><?php echo $row['room'] ?></td>
</tr>
<?php }?>
</tbody>
</table>

但是每当我选择行并按下删除按钮时,什么都没有发生。有什么我想念的吗?

最佳答案

The usage of form is entirely wrong on your HTML page. The form should appear as how i have done. Input type button is wrong you have to change to submit..

<?php 
if(isset($_POST['Delete']))
{
for($i=0;$i<count($_POST['checkbox']);$i++){
$ids= $_POST['checkbox'][$i];
$query2="DELETE FROM products WHERE serialid='".$ids."'";
mysqli_query($conn,$query2);
}
}
$query2="SELECT * FROM products";
$allresult = mysqli_query($conn,$query2);
?>
<form method="POST" action="index.php">
<input type="submit" class="btn btn-danger" name="Delete" value="Delete"/>
<table class="table table-striped table-hover table-responsive" id="inventoryTable">
<thead>
<tr>
<td>Serial ID</td>
<td>Name</td>
<td>Manufacturer</td>
<td>Keys</td>
<td>Description</td>
<td>Category</td>
<td>Block</td>
<td>Floor</td>
<td>Room</td>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($allresult)) { ?>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?php echo $row['serialid']; ?>"></td>
<td><?php echo $row['serialid']?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['manufacturer'] ?></td>
<td><?php echo $row['licensekeys'] ?></td>
<td><?php echo $row['description'] ?></td>
<td><?php echo $row['categoryname'] ?></td>
<td><?php echo $row['block'] ?></td>
<td><?php echo $row['floor'] ?></td>
<td><?php echo $row['room'] ?></td>
</tr>
<?php }?>
</tbody>
</table>
</form>

Wrap all the details in the <form> element.

关于php - 如何通过php中的复选框删除多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39241112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com