<form action="<?php echo $_SERVER['PHP_SELF'];?>" style="display:inline" method="post">
<input type="submit" name="del" value="Delete">
<br>
<?php
$con=mysql_connect("localhost","root") OR DIE ("cant connect to server".mysql_error());
mysql_select_db("bedanshare") OR DIE ("cannot select db".mysql_error());
$stud=mysql_query("SELECT * FROM studentreg");
$count=mysql_num_rows($stud);
echo "<table border='1'>";
echo "<th><center />#</th>";
echo "<th><center />Student Number</th>";
echo "<th><center />First Name</th>";
echo "<th><center />Last Name</th>";
echo "<th><center />E-mail</th>";
echo "<th><center />Username</th>";
echo "<th><center />Password</th>";
while($row=mysql_fetch_array($stud))
{
echo "<tr>";?>
<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value="<?php echo $row['ID']; ?>">
<?php
echo "<td><center />".$row['ID']."</td>";
echo "<td><center />".$row['Fname']."</td>";
echo "<td><center />".$row['Lname']."</td>";
echo "<td><center />".$row['EmailAddress']."</td>";
echo "<td><center />".$row['Username']."</td>";
echo "<td><center />".$row['Password']."</td>";
echo "</tr>";
}
echo "</table>";
if($del)
{
for($i=0;$i<$count;$i++)
{
$id=$checkbox[$i];
$dels=mysql_query("DELETE FROM studentreg WHERE ID='$id'");
}
}
?>
</form>
为什么代码不删除行?:( 请帮助。似乎没有数据受到影响。ID 是我的主键,但是当我单击删除时,没有任何反应。我认为我的查询没有错。顺便说一句,我使用复选框删除多行。