Talk the guys! I need to create a system that includes categories and subcategories ... however, these two must be in a single table with the columns id, category, category_id and exc. Does anyone know how I should do this? Thank you in advance!
<?php
if (!empty($_POST['formCategoria'])) {
include '../fn.php';
if (empty($_POST['categoria_id'])) {
s("INSERT INTO categoria (categoria_id) VALUES (NULL)");
$f = f("SELECT categoria_id FROM categoria ORDER BY id DESC LIMIT 1");
$_POST['id'] = $f['id'];
}
$categoria_id="";
if (!empty($_POST['categoria_id'])) {
$categoria_id=" categoria_id='" . $_POST['categoria_id'] . "', ";
}
s("UPDATE categoria SET
".$categoria_id."
categoria_id='" . $_POST['categoria_id'] . "'
WHERE id='" . $_POST['id'] . "'
");
?>
<script>
window.alert('Atualizado');
window.location = '../categorias';
</script>
<?php
exit;
}
if (!empty($_GET['categora_id'])) {
$categoria = f("SELECT * FROM categoria WHERE id=" . $_GET['categoria_id']);
}
?>
<div class="row">
<div class="container">
<div class="col-md-12">
<h3>Subcategoria</h3>
<a class="btn btn-xs btn-default" href="<?php echo $root; ?>categorias">Voltar</a>
<div class="br2"></div>
<div class="row">
<form id="formCategoria" action="<?php echo $root; ?>pg/edita-subcategoria.php" method="post">
<input type="hidden" name="formCategoria" value="ok">
<?php
if (!empty($_GET['id'])) {
?>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<?php
}
?>
<div class="col-md-3">
<div class="form-group">
<label>Subcategoria</label>
<input class="form-control" type="text" name="categoria_id"
value="<?php echo!empty($categoria_id['categoria_id']) ? $categoria_id['categoria_id'] : ''; ?>">
</div>
</div>
<div class="br2"></div>
<div class="col-md-12">
<div class="div-right">
<input type="submit" class="btn btn-default" value="<?php echo empty($_GET['id'])?'Cadastrar':'Atualizar'; ?>">
</div>
</div>
<div class="br2"></div>
<div class="br2"></div>
</form>
</div>
</div>
</div>