Hello,
I got this code:
<?php
//mysql connection
$dbconn = mysql_connect("localhost","root","password") or die();
mysql_select_db("imaccs_v1") or die();
$sqlquery = "SELECT * FROM clerks"; // query on table
$sqlresult = mysql_query($sqlquery, $dbconn);
$count = mysql_num_rows($sqlresult); // count query result
?>
<table width="400" border="1" cellspacing="1" cellpadding="0">
<tr><td> <form method="post" action="delete5.php">
<table width="400" border="1" 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>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td></tr>
<?php while($rows = mysql_fetch_assoc($sqlresult)){ ?>
<tr><td align="center" bgcolor="#FFFFFF">
<input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['id']?>" />
</td><td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['fname']; ?></td><td bgcolor="#FFFFFF"><?php echo $rows
['lname']; ?>
</td><td bgcolor="#FFFFFF"><?php echo $rows['email']; ?>
</td></tr>
<?php } ?>
<tr><td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete"></td></tr>
<?php
//mysql connection here
if($_POST['delete']) // from button name="delete"
{
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);
for($i=0;$i<$countCheck;$i++)
{
$del_id = $checkbox[$i];
$sql = "delete from test_mysql where id = $del_id";
$result = mysql_query($sql, $dbconn);
}
if($result)
{
echo "successful delete";
}
else
{
echo "Error: ".mysql_error();
}
}
?></table>
</form></td></tr></table>
Problem: Undefined index: delete in delete.php on line 31
Someone help me solve it.