1
deleta.php:
<?php
// quero transformar esse script em função e chama-lo no link
// deleta um unico post
include("config.php");
$id = $_GET['id'];
$sqlInsert = "DELETE FROM conteudo WHERE id = '$id'";
$deletaPost = mysqli_query($conecta,$sqlInsert);
if($deletaPost) {
header("Location: ".$_SERVER['HTTP_REFERER']."");
exit;
} else {
echo mysqli_error($conecta);
}
// o script abaixo deleta através de um checkbox, e elimina varios de uma vez.
// quero que esse seja o padrão, e o script acima seja uma função que só funcione quando chamada.
if( !empty( $_POST['deletar'] ) ) {
$groups = array_chunk( $_POST['deletar'], 50 );
foreach ( $groups AS $group ) {
$group = implode('\',\'', $_POST['deletar']);
$query = 'DELETE FROM conteudo WHERE id IN (\''. $group .'\')';
$deleta = mysqli_query($conecta, $query);
// executa a query
}
if($deleta) {
header("Location: ".$_SERVER['HTTP_REFERER']."");
exit;
} else {
echo mysqli_error($conecta);
}
} else {
header("Location: ".$_SERVER['HTTP_REFERER']."");
exit;
}
?>
HTML:
<a href="deleta.php?id=<?php echo $row['id']; ?>">Excluir</a>
How should I turn the delete script into a function, and then call on the link?
I want to do this because on the page deleta.php I already have another script, and the two are giving conflicts. With this, I decided to turn the script into a function and call it on the link. How to act
you can delete more than one record per link?
– rray
No, with a checkbox in another part of the code.
– Cobra