【发布时间】:2015-08-23 21:49:09
【问题描述】:
谁能告诉我下面的代码有什么问题?当我单击删除按钮时,它给了我一个错误
未定义索引复选框
尽管checkbox 是下面input 标记的名称。
我知道我没有编写删除查询,但这不是重点。我想回显$del_id,但我不断收到错误消息。
<?php
include 'connection.php';
if(isset($_POST['del'])){
$name=$_POST['checkbox'];
$del_id=implode(",", $name);
echo $del_id;
}
$sql="SELECT * FROM `student-reg`";
$result=mysqli_query($conn, $sql) or die(mysqli_error($conn));
echo "<table align='center' border='2'>
<tr>
<th>Mark</th>
<th>ID</th>
<th>First_Name</th>
<th>Last_Name</th>
<th>Roll_no</th>
<th>Degree</th>
</tr>
";
while($row=mysqli_fetch_assoc($result)){
$id=$row['Id'];
echo "
<tr>
<td><input type='checkbox' name='checkbox[]' value='".$row['Id']."'></td>
<td>{$id}</td>
<td>{$row['First_name']}</td>
<td>{$row['Last_name']}</td>
<td>{$row['Roll_no']}</td>
<td>{$row['Degree']}</td>
</tr>
";
}
?>
<html>
<body>
<form method="POST">
<input type="submit" value="Delete" name="del">
</form>
</body>
</html>
【问题讨论】:
-
只需使用
if(isset($_POST['checkbox'])) { }进行检查。在您真正点击“删除”按钮之前,它不可用。 -
您的复选框不在您的表单中。当你点击
submit时,只有<form>标签之间的<input>字段会被发送到服务器。 -
是的,这就是问题所在,谢谢流浪汉