PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function _delete( $id ) {
global $dbc;#database connect.. change to own settings.
echo "DELETE FROM DATABASE WHERE id IN ($ids)";
if (!is_array( $id ) || count( $id ) < 1) {
echo "<script> alert('Seleccione el artículo para suprimir'); window.history.go(-1);</script>n";
exit;
}
if (count( $id )) {
$ids = implode( ',', $id );
$dbc->setQuery( "DELETE FROM DATABASE WHERE id IN ($ids)" );
if (!$dbc->getError( )) {
# my db error Return change to your own settings
echo "<script> alert('".$dbc->getError( )."');
window.history.go(-1); </script>n";
}
}
}
_delete(array $POST checkbox);
EDIT:
Sorry my Bad.. ill leave the code but here for file handling
The file isn't in a database, it's just residing in a folder. I know I need to be using unlink but I think something in my foreach statement isn't populating the $deletethis variable properly. I also have a print_r ($deletethese); below all of this code and it does work properly. All of the checkboxes I select are populating the array so I know that's correct, they just don't delete.
Try echoing $deletethis as you're deleting it. Maybe the filename's wonky.
Is $deletethis a filename or is it a fully qualified file path? unlink() needs a fully qualified file path to work.
unlink()ing files directly from $_POST is VERY bad. I could easily just send my own POST variables with "/var/lib/mysqld" as a filename and BAM! - the mysql executable is gone.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
It seems the problem lies before the unlink(). I have echo'd the $count and it always shows zero, the count incrementing should happen right before the deletion.
$deletethis is not a fully qual file path, I can fix that easily enough though. I did try echoing $deletethis and got nada.
Scratch what I said before, I had put the print_r ($deletethese); after the closing brackets, not thinking it would make a difference. I tried the following code, just like you suggested. . .
And it did NOT print the array, why?! I also tried using print_r ($deletethese); after the echo for quantity of imgs deleted and it DID print the array, I'm even more confused but hopefully this helps.