2
I would like to know how I can delete more than one customer as selected by checkbox
. I have within a complete form:
<form method="post" action="../sys/del.php">
<?php
require "../sys/conexao.php";
$sql = mysqli_query($mysqli, "SELECT * FROM contato");
while ($aux = mysqli_fetch_array($sql)) {
$id = $aux['id_contato'];
$nome = $aux['nome'];
$email = $aux['email'];
$assunto = $aux['assunto'];
$mes = $aux['mensagem'];
$hora = $aux['hora'];
print"
<tr>
<td><input type=\"checkbox\" name=\"valor[]\" id=\"$id\" value=\"$id\"/></td>
<td class=\"mailbox-star\"><a href=\"\"><i class=\"fa fa-star text-yellow\"></i></a></td>
<td class=\"mailbox-name\"><a href=\"read-mail.html\">$nome</a></td>
<td class=\"mailbox-subject\"><b>Kamilla Peliculas - Contato</b> - $assunto</td>
<td class=\"mailbox-attachment\"></td>
<td class=\"mailbox-date\">$hora</td>
</tr>";}
mysqli_close($mysqli);
?>
</tbody>
</table><!-- /.table -->
</div><!-- /.mail-box-messages -->
</div><!-- /.box-body -->
<div class="box-footer no-padding">
<div class="mailbox-controls">
<!-- Check all button -->
<div class="btn-group">
<button type="submit" name="excluir" class="btn btn-default btn-sm"><i class="fa fa-trash-o"></i></button>
</div>
</form>
And this form sends to the page that will get the value of these checkbox
selected and delete, but it gives the following error:
Notice: Undefined index: valor in C: xampp htdocs novo sys del.php on line 5
Warning: Invalid argument supplied for foreach() in C: xampp htdocs new sys del.php on line 5
Notice: Undefined variable: val in C: xampp htdocs novo sys del.php on line 12
Someone can help me with this problem, I can’t find the mistake.
Code of the PHP page:
if(isset($_POST['excluir'])){
require_once"conexao.php";
foreach($_POST['valor'] as $ck){
$val = $v;
mysqli_query($mysqli, "DELETE FROM contato WHERE id_contato = '$val'");
echo"<script type=\"text/javascript\">alert(\"Campo Deletado Com Sucesso!\");
history.go(-1);</script>\n";
mysqli_close($mysqli);
}
}
I posted a solution to this issue: http://answall.com/questions/103910/delete-em-multiplos-posts-com-checkbox
– Bacco