我正在学习php,我是新来的。有人可以帮助我提供代码吗?删除按钮不起作用。我已经尝试了很多,但是我没有更多的想法。
<body>
<?php
if(isset($_POST['delete-btn'])) {
if(isset($_POST['selector'])) {
foreach ($_POST['selector'] as $selector) {
$stmt = $pdo->prepare('delete from mytable where id = :id');
$stmt->bindValue('id', $selector);
$stmt->execute();
}
}
}
?>
<form action="" method="post">
<input type="text" name="text" placeholder="insert a text">
<input type="submit" value="Insert" name="insert">
<input type="button" name="delete-btn" value="Delete">
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<th><input type="checkbox" id="checkBoxAll" /></th>
<th>id</th>
<th>Text</th>
</tr>
<?php
require 'insert.php';
$statement = $pdo->prepare("SELECT * FROM mytable");
$statement->execute();
while($row = $statement->fetch()) {
$id = $row['id'];
$name = $row['name'];
?>
<tr>
<td><input type="checkbox" name="selector[]" value="<?php echo $id; ?>"></td>
<td><?php echo $id ?></td>
<td><?php echo $name; ?></td>
</tr>
<?php } ?>
</table>
</form>
</body>
</html>
与删除部分有我的问题。
谢谢