I have a system that I did (I do not understand much of PHP) worked perfectly but after switching the server stopped the function of deleting only the selected checkboxes, it simply deletes everything.
I search all of them for database and command to display only the first 4 IDs (usually they are written with error in Bank - XML with problem that does not come from me).
Follows part of the code.
<form method="post" action="limpar_selecionados.php">
<?php
$query = sprintf("SELECT * FROM loja WHERE categoria = 'NOTEBOOK' ORDER BY nome ASC LIMIT 4");
$dados = mysql_query($query, $con) or die(mysql_error());
$linha = mysql_fetch_assoc($dados);
$total = mysql_num_rows($dados);
if($total > 0) {
do {
?>
<p> <input type="checkbox" name="chk[]" value="<?=$linha['id']?>" style="display:block;"/> </p>
<?php
}while($linha = mysql_fetch_assoc($dados));
}
?>
<?php
$query = sprintf("SELECT * FROM loja WHERE categoria = 'Smartphone' ORDER BY nome ASC LIMIT 4");
$dados = mysql_query($query, $con) or die(mysql_error());
$linha = mysql_fetch_assoc($dados);
$total = mysql_num_rows($dados);
if($total > 0) {
do {
?>
<p> <input type="checkbox" name="chk[]" value="<?=$linha['id']?>" style="display:block;"/> </p>
<?php
}while($linha = mysql_fetch_assoc($dados));
}
?>
<input type="submit" name="submit" value="Excluir Selecionados">
</form>
Clear_selected.php
<?php
print_r($_POST);
if(isset($_POST['chk'])){
$excluir = $_POST['chk'];
foreach ($_POST['chk'] as $item) {
$sql_deleta = "DELETE FROM 'loja' WHERE 'id' = '$item'";
mysql_query($sql_deleta);
}
}
?>