Ok. first of all, here's the page with the code:http://www.ficti0n.com/images.php
Now.
If you use the "delete checked", it works fine. You select the images you wanna delete, click the button, and those images get deleted.
But you will also see that under each image, there is a "delete" button, to delete that one image.
for some reason, it doesn't work. Instead of deleting that specific image, it deletes the last one.
<?php
echo '<table border="1"><tr>';
$query = "SELECT upload_id, name, size, caption, private FROM uploads";
$result = mysql_query($query);
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="form">';
while ($row = mysql_fetch_array($result)) {
if (($number % 4) == 0) {
echo '</tr><tr>';
}
$number ++;
echo '<td width="120">
<img src="./uploads/'.$row[1].'" height="115" width="115" /><br />
<input type="hidden" name="upload_id" value="'.$row[0].'" />
<input type="text" size="13" value="http://www.ficti0n.com/uploads/'. $row[1].'" /> <br />
<input type="submit" value="delete" name="delete_button" />('.$row[0].') <br />
<input type="checkbox" name="checked[]" value="'.$row[0].'" />
</td>';
} # end while loop
echo '</tr></table>';
// Delete individual --> this is the button that shows under each image
if (isset($_POST['delete_button'])) {
$query = "DELETE FROM uploads WHERE upload_id = '{$_POST['upload_id']}'";
#$result = mysql_query($query);
echo $query;
#header ("Location: images.php");
}
// Delete selected button
if (isset($_POST['delete_selected'])) {
if (!isset($all)) {
echo 'There are no images to be deleted';
} else {
$selected = NULL;
$key = NULL;
if (isset($_POST['checked'])) {
foreach ($_POST['checked'] as $key => $value) {
$selected .= "'".$value."', ";
}
$query = "DELETE FROM uploads WHERE upload_id IN ( ".substr($selected, 0, -2).") ";
$result = mysql_query($query) or die("Could not delete picture with id $key: " . mysql_error());
if ($result) {
header ("Location: {$_SERVER['PHP_SELF']}");
}
} else {
echo 'No image was selected.';
}
}
} # close if (isset($_POST['delete_selected']))
?>
<input type="submit" value="Delete selected" name="delete_selected" /></td>
</form>
You will see that at the end of the page, i echo my query.
Notice that no matter which "delete" button you click, the query always shows up as:
DELETE FROM uploads WHERE upload_id = '39'
the upload_id always shows up ad the ID of the last image