I'm trying to delete the rows selected with checkboxes with php code. html part
<form action="maincontrol.php" name="control" method="post">
<?php
require('dbconnect.php');
$result = mysql_query("SELECT * FROM soru");
echo "<table border='1' id='tumveriler'>
<tr>
<th></th>
<th>Index</th>
<th>Soru</th>
<th>Sorma Tarih</th>
<th>Cevap</th>
<th>Cevaplama Tarih</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input name='checkbox' type='checkbox' value='" . $row['index'] . "'" . " />";
echo "<td>" . $row['index'] . "</td>";
echo "<td>" . $row['soru'] . "</td>";
echo "<td>" . $row['sormadate'] . "</td>";
echo "<td>" . $row['cevap'] . "</td>";
echo "<td>" . $row['cevapdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<input type= "submit" name ="update" value="Update">
</form>
php part
<?php
require('dbconnect.php');
if (isset($_POST['control']) && !empty($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $id)
{
$query = "DELETE FROM soru WHERE `index` = '$id'";
$link = mysql_query($query);
if(!$link)
{
die('not worked: ' . mysql_error());
}
else
{
mysql_close($con);
echo 'worked';
}
}
}
?>
When I click update button I see a beautiful white screen. Nothing happens, no error dialogs... Help!
inputnamed "control" yet the PHP that's handling the delete hasisset($_POST['control']). Theifstatement most likely fails. Also theinputfor the checkboxes should include square brackets to tell PHP it's an array:<input name="checkbox[]" ... />.echo "<td>" . "<input name='checkbox[]' type='checkbox' value='" . $row['index'] . "'" . " />";and if your form doesn't include a field named "control", removeisset($_POST['control'])from theifstatement that in the script that deletes.