Mini Shell
<?
include"menu.php";
if($_POST){
$id = $_POST["id"];
include"conexao.php";
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to delete a record
$sql = "DELETE FROM tab_categoria WHERE id_categoria=$id";
// echo"$sql";
if ($conn->query($sql) === TRUE) {
echo "<script>
alert('EXCLUIDA COM SUCESSO! ');
window.location='categoriasdeempresas';
</script>";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
exit();
}
$tip = $_GET["tip"];
switch ($tip)
{
case "add":
$novacat = $_GET["novacat"];
$novacat = utf8_decode($novacat);
include"conexao.php";
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$sql = "INSERT INTO tab_categoria (categoria) VALUES ('$novacat')";
//echo"$sql";
if ($con->query($sql) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
$con->close();
echo"<script type='text/javascript'>
window.alert('SUCESSO!')
window.location='categoriasdeempresas';
</script>";
exit();
break;
case "editt":
$id = $_GET["id"];
$nomecat = $_GET["nomecat"];
echo"<center>
<form name=\"form1\" action=\"categoriasdeempresas.php\" method=\"GET\" >
<input type='hidden' name='tip' value='edit'>
<input type='hidden' name='id' value='$id'>
<input type=\"text\" name=\"nomefinal\" class = \"form-control animated bounceInleft\" value=\"$nomecat\" style=\"width:180px; margin-bottom:10px\">
<button type=\"submit\" class=\"btn btn-success\" value=\"\" style='width:100px;'>
<i class='fa fa-edit' style='font-size:18px'></i>
SALVAR
</button>
</form>
</center>
";
exit();
break;
case "edit":
$id = $_GET["id"];
$nomefinal = $_GET["nomefinal"];
$nomefinal = utf8_decode("$nomefinal");
include"conexao.php";
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$idd = base64_decode($idd);
$sql = "UPDATE tab_categoria SET categoria = '$nomefinal' WHERE id_categoria='$id' ";
// echo"$sql";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error updating record: " . $conn->error;
print'<script type="text/javascript" language=""> alert("OCORREU UM ERRO!"); </script>';
}
$conn->close();
echo"<script type='text/javascript'>
window.alert('SUCESSO!')
window.location='categoriasdeempresas';
</script>";
exit();
break;
}
echo"<center>
<form name=\"form1\" action=\"categoriasdeempresas.php\" method=\"GET\" >
<input type='hidden' name='tip' value='add'>
<input type=\"text\" name=\"novacat\" class = \"form-control animated bounceInleft\" placeholder=\"NOME DA CATEGORIA\" style=\"width:180px; margin-bottom:10px\">
<button type=\"submit\" class=\"btn btn-success\" value=\"\" style='width:100px;'>
<i class='fa fa-plus' style='font-size:18px'></i>
INCLUIR
</button>
</form>
</center>
";
?>
<div class="container">
<table class="table table-action">
<thead>
<tr>
<th class="t-medium"><h5><b>Categoria</b></h5></th>
<th class="t-small"><h5><b> </b></h5></th>
</tr>
</thead> <tbody>
<?php
// print_r($_GET);
// PEGA EMPRESA
include"conexao.php";
// conexão e seleção do banco de dados
$con = mysqlI_connect($host, $user, $pass, $db);
// executa a consulta
$sql = "SELECT * FROM tab_categoria order by categoria asc ";
// echo"$sql";
// inicio
$res = mysqli_query($con, $sql);
$total = mysqli_num_rows($res);
echo"<br><br><center> <b>Exibindo $total categorias</b></center>";
//echo"$sql";
// loop pelos registros
while ($f = mysqli_fetch_array($res))
{
$categoria = $f['categoria'];
$id_categoria = $f['id_categoria'];
$categoria = utf8_encode($categoria);
echo"<tr>";
echo"<td>$categoria</td>";
echo"<td><label>
<form name=\"form1\" action=\"categoriasdeempresas.php\" method=\"GET\" >
<input type='hidden' name='id' value='$id_categoria'>
<input type='hidden' name='nomecat' value='$categoria'>
<input type='hidden' name='tip' value='editt'>
<button type=\"submit\" class=\"btn btn-success\" value=\"\" style='width:90px;'>
<i class='fa fa-edit' style='font-size:18px'></i>
Editar
</button>
</form>
</label>
<script type=\"text/javascript\">
function pergunta$id_categoria(){
return confirm('Tem certeza que quer excluir a categoria $categoria?');
}
</script>
<label>
<form name=\"form1\" action=\"categoriasdeempresas.php\" method=\"POST\" >
<input type='hidden' name='id' value='$id_categoria'>
<input type='hidden' name='tip' value='exc'>
<button type=\"submit\" class=\"btn btn-danger\" value=\"\" style='width:90px;' onclick='return pergunta$id_categoria();'>
<i class='fa fa-trash-o' style='font-size:18px'></i>
Excluir
</button>
</form>
</label>
</td>";
}
echo"</tr>";
mysqli_close($con);
?> </tbody>
</table>
<p> </p>
<p><br>
<br>
</div>
Zerion Mini Shell 1.0