Error when registering data in the database :(

Asked

Viewed 49 times

0

I am trying to make a system of registration of companies, but it does not work. I am doing everything right to my view. The bank is the same, the variables are right and the functions are right. I don’t know what’s wrong. Can anyone help me? (Note: I am beginner in PHP programming).

<?php
// incluindo e fazendo conexão com o banco de dados
require_once "../action/server.php";

// iniciar a sessão - para poder usar variaves de sessão
session_start();

// Verificar se a variavel usuario já foi configurada pelo method post
if ( isset( $_POST["nome"] ) ) {
    $nome                   = $_POST["nome"];
    $email                  = $_POST["email"];
    $telefone               = $_POST["telefone"];
    $tipo_empresa           = $_POST["tipo_empresa"];
    $cnpj                   = $_POST["cnpj"]; 
    $endereco               = $_POST["endereco"]; 
    $complemento            = $_POST["complemento"];
    $numero                 = $_POST["numero"]; 
    $cidade                 = $_POST["cidade"]; 
    $uf                     = $_POST["uf"];
    $cep                    = $_POST["cep"]; 
    $uf                     = $_POST["uf"]; 
    $cidade                 = $_POST["cidade"]; 


    // inserir os dados no banco
    $cadastrar_empresa  = "INSERT INTO ds_empresa";
    $cadastrar_empresa .= "(nome, email, telefone, tipo_empresa, cnpj, endereco, complemento, numero, cidade, uf, cep, senha) ";
    $cadastrar_empresa .= "VALUES ";
    $cadastrar_empresa .= "('$nome', '$email', '$telefone', '$tipo_empresa', '$cnpj', '$endereco', '$complemento', '$numero', '$cidade', '$uf', '$cep', '$senha') ";

    echo "$cadastrar_empresa"; 

    $operacao_cadastrar_empresa = mysqli_query($conecta, $cadastrar_empresa);
    if ( !$operacao_cadastrar_empresa ) {
        die("Cadastro não foi feito! Erro:  " . mysqli_connect_errno());
    } else {
        header("location: login_empresa.php");
    }
}

?>

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>Cadastro de Empresa</title>

Cadastro de Empresa

                <!-- (nome, email, senha, cnpj, cep, telefone, complemento, numero, categoria, tipo_empresa, uf, cidade --> 

                <form  action="cadastro_empresa.php" method="post">
                    <div class="form-row">
                        <div class="form-group col-md-6">
                        <label for="nome">Nome</label>
                        <input type="text" class="form-control" id="nome" name="nome" placeholder="Nome">
                        </div>
                        <div class="form-group col-md-6">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" id="email" name="email" placeholder="Email">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-6">
                        <label for="inputEmail4">Confirmar Email</label>
                        <input type="email" class="form-control" id="inputEmail4" placeholder="Confirmar Email">
                        </div>
                        <div class="form-group col-md-6">
                        <label for="senha">Senha</label>
                        <input type="password" class="form-control" id="senha" name="senha" placeholder="Senha">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tipo_empresa">Tipo de Empresa: </label>
                        <input type="text" class="form-control" id="tipo_empresa" name="tipo_empresa" placeholder="Tipo da Sua Empresa...">
                    </div>
                    <div class="form-group">
                        <label for="telefone">Telefone Fixo:</label>
                        <input type="text" class="form-control" id="telefone" name="telefone" placeholder="Telefone">
                    </div>
                    <div class="form-group">
                        <label for="uf">Estado</label>
                        <input type="text" class="form-control" id="uf" name="uf" placeholder="Estado">
                    </div>
                    <div class="form-group">
                        <label for="cidade">Cidade</label>
                        <input type="text" class="form-control" id="cidade" name="cidade" placeholder="Sua Cidade">
                    </div>
                    <div class="form-group">
                        <label for="cep">CEP</label>
                        <input type="text" class="form-control" id="cep" name="cep" placeholder="Seu CEP">
                    </div>
                    <div class="form-group">
                        <label for="endereco">Endereço</label>
                        <input type="text" class="form-control" id="endereco" name="endereco" placeholder="Seu Endereço">
                    </div>
                    <div class="form-group">
                        <label for="numero">Número</label>
                        <input type="text" class="form-control" id="numero" name="numero" placeholder="Seu Número">
                    </div>
                    <div class="form-group">
                        <label for="complemento">Complemento</label>
                        <input type="text" class="form-control" id="complemento" name="complemento" placeholder="Complemento">
                    </div>
                    <div class="form-group">
                        <label for="cnpj">CNPJ</label>
                        <input type="text" class="form-control" id="cnpj" name="cnpj" placeholder="Seu CNPJ">
                    </div>
                    <button type="submit" class="btn btn-primary">Cadastrar</button>
                    </form>



                </div>
            </div>
        </div>
        </div>
    </div>
</div>
<!-- JavaScript (Opcional) -->
<!-- jQuery primeiro, depois Popper.js, depois Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

Code of the seat configuration:

$servidor = "localhost";
$usuario = "root";
$senha = "";
$banco = "db_ipac";

// Realizando conexão com o Banco
$conecta = mysqli_connect($servidor, $usuario, $senha, $banco);

// Verificando se ocorreu algum erro na conexão
if ( mysqli_connect_errno() ) {
    die("Conexão falhou: " . mysqli_connect_errno());
}

?>

  • Displays the code of the.php register ? If possible the table to see the database fields as well

  • The code page is the same as the question. I’m sending the form to the same page.

  • Bank: CREATE TABLE ds_empresa ( id_empresa int(11) NOT NULL, nome varchar(255) NOT NULL, email varchar(100) NOT NULL, telefone int(10) NOT NULL, tipo_empresa varchar(100) NOT NULL, cnpj char(14) NOT NULL, tipo_empresa_id int(11) NOT NULL, endereco varchar(255) DEFAULT NULL, complemento varchar(255) DEFAULT NULL, numero varchar(5) DEFAULT NULL, cidade varchar(60) DEFAULT NULL, uf char(2) DEFAULT NULL, cep char(8) DEFAULT NULL, senha varchar(255) DEFAULT NULL ) ENGINE=Innodb DEFAULT CHARSET=utf8;

  • When you give the echo of the $register company, has how to show the result here?

  • One more thing I realized, if that table dump you posted in the comment is the same as your local bank then it will give error in your query because it is missing 2 mandatory variables, id_company and tip_empresa_id. I believe you wanted the id_emrpesa to be auto_increment and the type_empresa_id is a foreign_key from another table.

  • 1

    Hi. The $Uf variable is repeated and missing fill in the "password" column. Check.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.