Error saving bank records

0

I have a normal form with a normal page to import the information into a normal bank table, but for some reason it goes straight to the die and does not save the information.

Form:

<form method="POST" action="update-cli.php">
<div class="container">
  <div class="row">
    <div class="col-lg-8 col-md-10 mx-auto">
      <div class="form-group">
        <label for="NOME">Nome:</label>
        <input type="text" class="form-control" id="NOME" name="NOME" placeholder="Nome do cliente">
      </div>
      <div class="form-group">
        <label for="DATA">Data de nascimento:</label>
        <input type="text" class="form-control" id="DATA" name="DATA" placeholder="Data de Nascimento do cliente">
      </div>
        <div class="form-group">
        <label for="ENDERECO">Endereço:</label>
        <input type="text" class="form-control" id="ENDERECO" name="ENDERECO" placeholder="Endereço do consultório">
      </div>
      <div class="form-group">
        <label for="TELEFONE">Telefone:</label>
        <input type="text" class="form-control" id="TELEFONE" name="TELEFONE" placeholder="Telefone fixo">
      </div>
      <div class="form-group">
        <label for="CELULAR">Celular:</label>
        <input type="text" class="form-control" id="CELULAR" name="CELULAR" placeholder="Telefone celular">
      </div>
      <button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
    </div>
  </div>
</div>
</form>

Import page:

<?php

    $nome = $_POST['NOME'];
    $data = $_POST['DATA'];
    $endereco = $_POST['ENDERECO'];
    $telefone = $_POST['TELEFONE'];
    $celular = $_POST['CELULAR'];

    $strcon = mysqli_connect('localhost','root','', 'sis_tam') or die('Erro ao conectar ao banco de dados');
    $sql = "INSERT INTO clientes VALUES ('$nome', '$data', '$endereco', '$telefone', '$celular')"; 
    mysqli_query($strcon,$sql) or die("Erro ao tentar cadastrar registro");
    mysqli_close($strcon);

    echo '<script type="text/javascript">
            alert("Salvo com Sucesso !");
            window.history.go(-1);
        </script>';

?>

Table in the bank:

  

ID NAME TELEPHONE NUMBER DATE TELEPHONE

Can anyone point me to the problem? Thank you

Bank structure:

    
asked by anonymous 24.01.2018 / 00:08

1 answer

2

Your code SQL is generating error 1136: Column count does not match value count at row 1

This happens because your table has 6 columns and you are passing 5, even though the ID is auto-increment, you need to specify in which columns you are going to write the data, your $sql should be like this

$sql = "INSERT INTO clientes (NOME, DATA, ENDERECO, TELEFONE, CELULAR) VALUES ('$nome', '$data', '$endereco', '$telefone', '$celular')";

To find this type of error the easiest way and give echo in your variable $sql and execute the generated code directly in the database manager, it will probably point the error to you.

Hope it helps!

    
24.01.2018 / 11:39