How to register date of birth in bd? [closed]

1

How to register date of birth in bd?

Codethattakesform:

$data=$_POST['dtn'];$dataP=explode('/',$data);$dataBd=$dataP[2].'-'.$dataP[1].'-'.$dataP[0];

functionthatsendsdatatobd:

<?phpinclude("conecta.php");

function insereUsuario($conexao, $dataBd) {
    $query = "insert into usuarios (dataBd) values ({$dataBd})";
    return mysqli_query($conexao, $query);
}
    
asked by anonymous 20.10.2017 / 15:13

3 answers

1

The Insert statement depending on the data type of the column can record a value as shown below.

1 - No quotation marks

SQL, with column dataBd being type Valores de Tempo

insert into usuarios (dataBd) values (2015-10-20)

Resultado (tipo DATE): 0000-00-00

Resultado (tipo DATETIME): 0000-00-00 00:00:00

SQL, the column dataBd being type Valores String or Valores Numéricos

insert into usuarios (dataBd) values (2015-10-20)

Resultado: 1985

2 - With quotation marks

SQL, with column dataBd being type Valores String

insert into usuarios (dataBd) values ('2015-10-20')

Resultado: 2015-10-20

SQL, with column dataBd being type Valores Tempo

insert into usuarios (dataBd) values ('2015-10-20')

Resultado (tipo DATETIME): 2015-10-20 00:00:00

Resultado (tipo DATE): 2015-10-20

SQL, with column dataBd being type Valores Numéricos

insert into usuarios (dataBd) values ('2015-10-20')

Resultado: 2015

Conclusion

For columns of type type or string put quotation marks in the value

$query = "insert into usuarios (dataBd) values ('{$dataBd}')";
    
23.10.2017 / 19:13
0

Try to add date quotes to query.

insert into table (dt) values('2017-10-26');
    
20.10.2017 / 15:22
0

Good morning
I do the following INSERT values in the DB. (mysql)

$pid_paciente=$_POST['pid_paciente'];
$pid_horario=$_POST['pid_horario'];
$pdata_consulta = $_POST['pdata_consulta'];
$sql =  " Insert into consulta " .          
        " ( id_paciente_fk, id_m_h_fk,  id_convenio_fk, data_consulta)" .
        " values " .
        " ( ".$pid_paciente.",".$pid_horario.", 0,'" .$pdata_consulta. "')";


$resultado = mysql_query($sql, $conexao) or die(mysql_error()); 

This is 100% GUARANTEED :). For ONE insert to go wrong we have several reasons. But in your question this DATE OF BIRTH and the error is only returning the YEAR. Home AO it seems the variable $ _POST ['dtn'] only has the year inside.
To check what's inside the $ _POST ['dtn'] I would do so:

$data = $_POST['dtn'];
echo $data . ' a<br>';
$dataP = explode('/', $data);
echo $dataP . ' a<br>';
$dataBd = $dataP[2].'-'.$dataP[1].'-'.$dataP[0];
echo $dataBd . ' a<br>';
exit;

I hope you have given some light to you :)
Hugs.

    
20.10.2017 / 16:06