Category Bank link
Sub Category Bank link
See, when I create the categories and include the subcategories in them, they are simply adding in all categories, I have reviewed the code several times and I do not understand. The IDs remain at "0". What would be the path to error?
<div id="configs">
<h1>Cadastrar/Excluir Categorias</h1>
<div class="cadastra">
<form action="" method="post" enctype="multipart/form-data">
<label>
<span>Categoria</span>
<input type="text" name="categoria" />
</label>
<input type="hidden" name="cadastrar" value="categoria" />
<input type="submit" value="Cadastrar" />
</form>
</div><!-- cadastra -->
<div class="exibe">
<ul>
<?php
$listaCats = BD::conn()->prepare("SELECT * FROM 'categorias' ORDER BY id DESC");
$listaCats->execute();
if($listaCats->rowCount() == 0){}else{
while($categoria = $listaCats->fetchObject()){
?>
<li><?php echo $categoria->nome;?> <a href="?pagina=categorias&excluir=sim&cat=<?php echo $categoria->id;?>"><img src="imgs/btn_del.png" border="0" width="17" /></a></li>
<?php }}?>
</ul>
</div><!-- exibe -->
<?php if(isset($_POST['cadastrar']) && $_POST['cadastrar'] == 'categoria'){
$categoria = strip_tags(filter_input(INPUT_POST, 'categoria'));
if($categoria == ''){
echo '<script>alert("Informe o nome da categoria!");location.href="?pagina=categorias"</script>';
}else{
$slugCat = $painel->slug($categoria);
$cadastrar = BD::conn()->prepare("INSERT INTO 'categorias' (nome, slug) VALUES (?,?)");
if($cadastrar->execute(array($categoria, $slugCat))){
echo '<script>alert("Categoria cadastrada com sucesso!");location.href="?pagina=categorias"</script>';
}else{
echo '<script>alert("Erro ao cadastrar categoria!");location.href="?pagina=categorias"</script>';
}
}
}
if(isset($_GET['excluir']) && $_GET['excluir'] == 'sim'){
$cat = strip_tags((int)$_GET['cat']);
$excluir = BD::conn()->prepare("DELETE categorias, subcat FROM categorias LEFT JOIN subcat ON(categorias.id = subcat.id_cat) WHERE categorias.id = ?");
if($excluir->execute(array($cat))){
echo '<script>alert("Categoria excluída com sucesso!");location.href="?pagina=categorias"</script>';
}else{
echo '<script>alert("Erro ao excluir categoria!");location.href="?pagina=categorias"</script>';
}
}
?>
</div><!-- configs -->