<?php require_once "cabecalho.php"; require_once "conecta.php"; //ARQUIVO QUE FAZ A CONEXÃO COM O BANCO require_once "banco-categoria.php"; require_once "autoload.php"; //require_once("categoria.php") ?> <?php $categoria = new Categoria(); $categoria->setNome($_POST['nome']); $inseriuCategoria = insereCategoria($conexao, $categoria); if ($inseriuCategoria) { header("Location:categoria-formulario-listagem.php?cadastrado=true"); } else { header("Location:categoria-formulario-listagem.php?cadastrado=false"); }
<?php insereCategoria($_GET["catNome"], $_GET["catDesc"]); function insereCategoria($strNomeCateg, $strDescCateg) { $con = odbc_connect("DRIVER={SQL Server}; SERVER=i9yueekhr9.database.windows.net;\n\t\t\tDATABASE=lotus;", "TSI", "SistemasInternet123"); if (validaCategoria($strNomeCateg) == 0) { if (strlen($_GET["catNome"]) > 0 && strlen($_GET["catDesc"]) > 0) { $SQL = "INSERT INTO CATEGORIA(nomeCategoria, descCategoria)\n Values(UPPER('" . $strNomeCateg . "'), UPPER('" . $strDescCateg . "'))"; odbc_exec($con, $SQL); } else { echo "Favor preencher todos os campos"; } } else { echo "Categoria " . $strNomeCateg . " ja cadastrada."; } } function validaCategoria($strNomeCateg) { $con = odbc_connect("DRIVER={SQL Server}; SERVER=i9yueekhr9.database.windows.net;\n\t\t\tDATABASE=lotus;", "TSI", "SistemasInternet123"); $SQL = "select count(*) as 'QTD' from categoria where nomeCategoria = '" . $strNomeCateg . "'"; $res = odbc_exec($con, $SQL); $RFP = odbc_fetch_array($res); if ($RFP['QTD'] >= 1) { return 1; } else { return 0; } }