0
I have a system that I did (I don’t know much about PHP) worked perfectly but after switching server stopped working the function of deleting only the selected checkbox, it simply deletes everything.
I search all of them from database and have display only the first 4 ID (usually are saved with error in Database - XML 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>
Clean_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);
}
}
?>
Only with this code can not explain this behavior. Even if short_tags is disabled it would not erase all records. It must be something else.
error_reporting(E_ALL);
– Marcos Regis