i check the box(s) and it deletes them,but after i still see them in the list.when i refresh the page then they're gone. $query = mysql_query("select id, title, thumbnail, file from games") or die(mysql_error()); while($row = mysql_fetch_array($query)) { if (!file_exists('../' . $row['thumbnail'])) { echo '<form action="broken_files.php" method="POST" enctype="multipart/form-data">'; echo $row['id'] . ''; echo ' <input type="checkbox" name="checkbox[]" value="'.$row['id'].'"> <br />'; } } echo' <input type="submit" value="delete" /> </form>'; $checked = $_POST['checkbox']; $count = count($checked); for($i=0; $i < $count; $i++) { $query = "DELETE FROM games WHERE id='".$checked[$i]."'"; mysql_query($query); } PHP:
You're deleting them *after* echoing the list to the browser. Maybe put the delete stuff in a seperate PHP file, then header() back to your list page.
@zodiac try this <?php if ($_POST) { foreach ($_POST['checkbox'] as $delete_id) { $query = 'DELETE FROM games WHERE id="'.$delete_id.'"'; mysql_query($query); echo '<strong>'.$delete_id.'</strong> DELETED!<br />'; } } else { ?> <form action="broken_files.php" method="POST"> <?php $query = mysql_query("select id, title, thumbnail, file from games") or die(mysql_error()); while($row = mysql_fetch_array($query)) { if (!file_exists('../' . $row['thumbnail'])) { echo $row['id']. '<input type="checkbox" name="checkbox[]" value="'.$row['id'].'"> <br />'; } } ?> <input type="submit" value="Delete" /> </form> <?php } ?> PHP: