Problem in registering an item [closed]

-2

Hello there is an error where it does not return to the defined page, but in the url it appears that it enters the product control page that has been defined. The page simply turns white.

This is the form.

<form class="" method="post" action="controleProduto.php">
        <h1 class="">
          <b>Adicione Produtos</b>
        </h1>
        <div class="form-group">
          <label for="nome">
            <b>Nome:</b>
          </label>
          <input type="text" class="form-control" placeholder="Nome do Produto" id="nome" name="nome"> </div>
        <div class="form-group">
          <label for="valor">
            <b>Valor:</b>
          </label>
          <input type="text" class="form-control" id="valor" name="valor" placeholder="Valor do produto" > 
        </div>
        <button type="submit" class="btn btn-success" name="opcao" id="Cadastrar">Confirmar
        </button>
        <a href="paginaSessao.php" class="btn btn-light">
          <b>Voltar</b>
        </a>
      </form>

This is the file called after the form "product_product".

include 'crudProduto.php';

if(isset($_POST["opcao"])){

$opcao = $_POST["opcao"];

if($opcao=="Cadastrar"){
    $nome=$_POST["nome"];
    $valor=$_POST["valor"];
    cadastraProduto($nome,$valor);
    header("Location: paginaInicial.php");
}
    else if($opcao=="Alterar"){
        $codigo=$_POST["codigo"];
        $nome=$_POST["nome"];
        $valor=$_POST["valor"];
        alterarProduto($codigo, $nome, $valor);
        header("Location: visualizarProduto.php");
    }
    else if($opcao=="Excluir"){
        $codigo=$_POST["codigo"];
        excluirProduto($codigo);
        header("Location: visualizarProduto.php");
    }

This is the file that contains the functions. "CrudProduct"

include 'conexaoBD.php';
function cadastraProduto($nome,$valor){
    conectar();
    query("INSERT INTO produto (nome, valor) VALUES('$nome',$valor)");
    fechar();
}
    
asked by anonymous 21.09.2018 / 03:37

1 answer

3

The page goes white because in controleProduto.php you are making conditional test declarations that according to your code have no logic. You are defining a button as follows:

<button type="submit" class="btn btn-success" name="opcao" id="Cadastrar">Confirmar</button>

In your controleProduto.php file you are checking if it has the value attribute equal to "Cadastrar", "Alterar" e "Excluir" which obviously is incorrect because in its HTML not even the value attribute of the button element was defined.

    
21.09.2018 / 03:49