hi all.
I have some problem. I want to make Delete multiple rows in mysql with check box.
so I did it below.
but delete doesn't work. could you tell me where is wrong ?
<?php
include'conn.php';
mysql_select_db("auction")or die("cannot select DB");
$sql="SELECT * FROM family";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>relationship</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>tel</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>addr</strong></td>
</tr>
<?php
while($row = mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['relationship']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $row['relationship']; ?></td>
<td bgcolor="#FFFFFF"><? echo $row['name']; ?></td>
<td bgcolor="#FFFFFF"><? echo $row['tel']; ?></td>
<td bgcolor="#FFFFFF"><? echo $row['addr']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM family WHERE relationship='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<script>
alert('delete')
location.href = 'fam_list.php'
</script>";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>