Zero recording in the database!

Asked

Viewed 55 times

1

I created my form, and I did the recording test in the BD. When the field is null, it shows the error message. When fields are filled in, it shows the recorded data message successfully, but when I check the blank of data, there is no recorded data; I can’t identify the mistake. The codes are below:

Connection:

<?php    
$host = "localhost"; 
$user = "cnsmaxim_teste1"; 
$pass = ""; 
$banco = "cnsmaxim_teste"; 

$conexao = mysql_connect($host, $user, $pass) or die (mysql_error());
mysql_select_db($banco);
?>

Inserts:

<?php
    include "conecta_mysql.inc";

$tAut       =$_POST ["tAut"];
$tPrest     =$_POST ["tPrest"];
$tCart      =$_POST ["tCart"];
$cDadm      =$_POST ["cDadm"];
$tNome      =$_POST ["tNome"];
$tNasc      =$_POST ["tNasc"];
$tCnpj      =$_POST ["tCnpj"];
$tNomecont  =$_POST ["tNomecont"];
$tCodcnes   =$_POST ["tCodcnes"];
$tProf      =$_POST ["tProf"];
$tEsp       =$_POST ["tEsp"];
$tConsr     =$_POST ["tConsr"];
$tNcons     =$_POST ["tNcons"];
$tCbos      =$_POST ["tCbos"];
$tDatatm    =$_POST ["tDatatm"];
$tTab       =$_POST ["tTab"];
$tCodp      =$_POST ["tCodp"];


$sql = "INSERT INTO tabteste VALUES ";
$sql .= "('$tAut', '$tPrest', '$tCart', '$cDadm', '$tNome', '$tNasc', '$tCnpj', '$tNomecont', '$tCodcnes', '$tProf', '$tEsp', '$tConsr', '$tNcons', '$tCbos', '$tDatatm', '$tTab', '$tCodp')";
$resultado = mysql_query ($sql);
echo "Dados salvos com sucesso!";
mysql_close ($conexao);
?>

Checks:

<html>
<head>
    <meta name="description" content="Guia de Consulta CNS"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="_css/style.css" />
</head>
<body>


<?php

$tAut       =$_POST ["tAut"];
$tPrest     =$_POST ["tPrest"];
$tCart      =$_POST ["tCart"];
$cDadm      =$_POST ["cDadm"];
$tNome      =$_POST ["tNome"];
$tNasc      =$_POST ["tNasc"];
$tCnpj      =$_POST ["tCnpj"];
$tNomecont  =$_POST ["tNomecont"];
$tCodcnes   =$_POST ["tCodcnes"];
$tProf      =$_POST ["tProf"];
$tEsp       =$_POST ["tEsp"];
$tConsr     =$_POST ["tConsr"];
$tNcons     =$_POST ["tNcons"];
$tCbos      =$_POST ["tCbos"];
$tDatatm    =$_POST ["tDatatm"];
$tTab       =$_POST ["tTab"];
$tCodp      =$_POST ["tCodp"];

//Verifica se o campo não está em branco.
if (empty($tAut))
{
  $error[] = 'Preenchimento da Autorização obrigatório!<br>';
}
//Verifica se o campo não está embranco.

if (empty($tPrest))
    {
        $error[] = 'Preenchimento do Número da Guia do Prestador obrigatório!<br>';
    }
//Verifica se o campo não está em branco.

    if (empty($tCart))
    {
        $error[] = 'Preenchimento do Número da Carteirinha obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($cDadm)) {
        $error[] = 'Preenchimento da Data de Admissão obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tNome)) {
        $error[] = 'Preenchimento do Nome obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tNasc)) {
        $error[] = 'Preenchimento da Data de Nascimento obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tCnpj)) {
        $error[] = 'Preenchimento do CNPJ obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tNomecont)) {
        $error[] = 'Preenchimento do Nome do Contratado obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tCodcnes)) {
        $error[] = 'Preenchimento do Código CNES obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tProf)) {
        $error[] = 'Preenchimento  do Profissional Executante obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tEsp)) {
        $error[] = 'Preenchimento da Especialidade obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tConsr)) {
        $error[] = 'Preenchimento do Conselho Regional obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tNcons)) {
        $error[] = 'Preenchimento do Número do Conselho obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tCbos)) {
        $error[] = 'Preenchimento do Número do CBOS obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tDatatm)) {
        $error[] = 'Preenchimento da Data de Atendimento obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tTab)) {
        $error[] = 'Preenchimento da Tabela  obrigatório!<br>';

    }
//Verifica se o campo não está em branco.
    if (empty($tCodp)) {
        $error[] = 'Preenchimento do Código do Procedimento obrigatório!<br>';

    }

if (isset($error)){ // se houve erro
    foreach($error as $msg) {
        echo $msg;
    }
} else { // não houve erro
    $error[] = 'Todos os campos preenchidos corretamente!';
    include "insere.php";
}
?>
</body>
</html>
  • 2

    Do so to display a possible error, $resultado = mysql_query ($sql) or die(mysql_error());

  • What is your version of PHP?

  • In addition to your PHP version, is your PHP.INI configured to display errors? display_errors = on? Put this at the beginning of your code: ini_set('display_errors', 1); error_reporting(E_ALL);

  • @Allanandrade I’m using Phpstorm 2016.1.2

  • 1

    Shouldn’t you specify columns in your query ? Ex: INSERT INTO tabteste (coluna_tAut, coluna_tPrest, etc.. ) VALUES ('$tAut', '$tPrest', etc...)...

  • @rray I did as you said and the data is recording. But there are two fields that do not write. taut and tPrest

  • You tried to print their value?

  • @rray Yes. In fact, they are the same as the other fields. Even filled, in the database they are without number. taut records as 0 and tPrest null.

  • 1

    It may be that the name of the fields in the form are different from those captured by the post, could put the result of: echo $sql; in the question.

  • 1

    The form was missing identification equal to the post!

  • The post is not passing to the other file.

  • Managed to solve?

  • @rray Yes I did. Thank you!!

Show 8 more comments
No answers

Browser other questions tagged

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