martynball
01-19-2010, 11:23 AM
<?php
//**************************//
// Delete Selected Files //
//**************************//
//Variables
$values = $_POST['value'];
$i = 0;
//Select checked items
if (isset($_POST['DelSel'])) {
$count = count($values);
echo "Deleted records: ";
while ($i < $count) {
echo "$values[$i], ";
//Delete record
$delete = "DELETE FROM uploaded_files WHERE ID='$values[$i]'";
$result = mysql_query ($delete);
if (!$result)
{
die('Error: ' .mysql_error());
}
$i++;
} //End While
}
?>
$_POST[‘value’] is a checkbox which has the value of the primary key in the database. So for an example, it would be 201.
When the DelSel submit button is clicked the selected values are counted, whilst the number of values are higher then $i (0), records should be deleted for each value.
But for some reason if I only select one checkbox, nothing is deleted. And if I select multiple checkboxes at least one row is left.
//**************************//
// Delete Selected Files //
//**************************//
//Variables
$values = $_POST['value'];
$i = 0;
//Select checked items
if (isset($_POST['DelSel'])) {
$count = count($values);
echo "Deleted records: ";
while ($i < $count) {
echo "$values[$i], ";
//Delete record
$delete = "DELETE FROM uploaded_files WHERE ID='$values[$i]'";
$result = mysql_query ($delete);
if (!$result)
{
die('Error: ' .mysql_error());
}
$i++;
} //End While
}
?>
$_POST[‘value’] is a checkbox which has the value of the primary key in the database. So for an example, it would be 201.
When the DelSel submit button is clicked the selected values are counted, whilst the number of values are higher then $i (0), records should be deleted for each value.
But for some reason if I only select one checkbox, nothing is deleted. And if I select multiple checkboxes at least one row is left.